Last active
August 29, 2015 14:08
-
-
Save kazmura11/27a84ea9aba7a507253d to your computer and use it in GitHub Desktop.
RVO/NRVOのテスト
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
#include <iostream> | |
// フツーこんなのなしだけどstringを継承したデバッグ用のクラス | |
class mystring : public std::string { | |
public: | |
// コンストラクタ | |
mystring() : std::string() | |
{ | |
std::cout << "mystring constructor" | |
<< " mystring() called!" << std::endl; | |
} | |
mystring(const char *str) : std::string(str) | |
{ | |
std::cout << "mystring constructor" | |
<< " mystring(const char *str) called!" << std::endl; | |
} | |
mystring(const std::string &s) : std::string(s) | |
{ | |
std::cout << "mystring constructor" | |
<< " mystring(const std::string &s) called!" << std::endl; | |
} | |
// コピーコンストラクタ | |
mystring(const mystring &rhs) : std::string(rhs.c_str()) | |
{ | |
std::cout << "mystring copy constructor" | |
<< " mystring(const mystring &rhs) called!" << std::endl; | |
} | |
// 代入演算子 | |
mystring &operator=(const char *str) | |
{ | |
std::cout << "mystring assignment operator" | |
<< " mystring &operator=(const char *str) called!" << std::endl; | |
std::string::operator=(str); | |
return *this; | |
} | |
mystring &operator=(const std::string& s) | |
{ | |
std::cout << "mystring assignment operator" | |
<< " mystring &operator=(const std::string& s) called!" << std::endl; | |
std::string::operator=(s); | |
return *this; | |
} | |
mystring& operator=(const mystring& rhs) | |
{ | |
std::cout << "mystring assignment operator" | |
<< " mystring &operator=(const mystring& rhs) called!" << std::endl; | |
std::string::operator=(rhs.c_str()); | |
return *this; | |
} | |
}; | |
mystring test3() | |
{ | |
std::cout << "function test3 called!!" << std::endl; | |
mystring str = "test"; | |
return str; | |
} | |
mystring test4() | |
{ | |
std::cout << "function test4 called!!" << std::endl; | |
return mystring("test"); | |
} | |
int main() | |
{ | |
std::cout << "テスト3_a" << std::endl; | |
mystring str3_a = test3(); | |
std::cout << "[" << str3_a << "]" << std::endl; | |
std::cout << "テスト4_a" << std::endl; | |
mystring str4_a = test4(); | |
std::cout << "[" << str4_a << "]" << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment