When can copy elision occur in c++ (apart from RVO and NRVO) -
i understand copy elision can occur in cases other when returning function. i'm not able find evidence of it. can give example of when copy elision occur?
i've tried following, none of 3 copies optimised out
class mystring { public: mystring(const char* str) : mystr(str) { } mystring(const mystring& str) : mystr(str.mystr) { } std::string mystr; }; class myclass { public: myclass(mystring str) : mystring(str) {} mystring mystring; }; int main() { mystring test("hello"); std::cout << myclass(test).mystring.mystr << std::endl; return 0; }
Comments
Post a Comment