Created
March 21, 2017 08:10
-
-
Save m5knt/49fe7fa398cf57f9b54ca3bac6a40dcd to your computer and use it in GitHub Desktop.
C++のコンテナ挙動確認用クラス
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Foo; | |
std::ostream& operator<<(std::ostream& out, const Foo& self); | |
struct Foo : std::string { | |
typedef std::string Base; | |
~Foo() { | |
std::cout << "dtor : " << | |
std::addressof(*this) << | |
" " << *this << std::endl; | |
} | |
Foo() : std::string() { | |
std::cout << "default cstr : " | |
<< std::addressof(*this) << | |
" " << *this << std::endl; | |
} | |
Foo(const std::string& str) : std::string(str) { | |
std::cout << "ctor str : " << | |
std::addressof(*this) << | |
" " << *this << std::endl; | |
} | |
Foo(const Foo& other) : std::string(other) { | |
std::cout << "copy ctor : " << | |
"from " << std::addressof(other) << | |
" to " << std::addressof(*this) << | |
" " << *this << std::endl; | |
} | |
Foo(Foo&& other) : std::string(std::move(other)) { | |
std::cout << "move ctor : " << | |
"from " << std::addressof(other) << | |
" to " << std::addressof(*this) << | |
" " << *this << std::endl; | |
} | |
auto operator=(const Foo& other) -> Foo& { | |
std::string::operator=(other); | |
std::cout << "copy : " << | |
"from " << std::addressof(other) << | |
" to " << std::addressof(*this) << | |
" " << *this << std::endl; | |
return *this; | |
} | |
auto operator=(Foo&& other) -> Foo& { | |
std::string::operator=(std::move(other)); | |
std::cout << "copy : " << | |
"from " << std::addressof(other) << | |
" to " << std::addressof(*this) << | |
" " << *this << std::endl; | |
return *this; | |
} | |
}; | |
std::ostream& operator<<(std::ostream& out, const Foo& self) { | |
return out << self.c_str(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment