Created
June 27, 2013 10:26
-
-
Save borisbat/5875445 to your computer and use it in GitHub Desktop.
On &&
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
class Report | |
{ | |
public: | |
Report() : i_am_dead(false) { cout << " Report();" << endl; } | |
Report(const Report & ) { cout << " Report(const Report&);" << endl; }; | |
Report(Report && h) { cout << " Report(&&);" << endl; h.i_am_dead = true; } | |
Report & operator = (const Report&) { cout << " Report::=(const Report&);" << endl; return *this; }; | |
~Report() { cout << " ~Report() i_am_dead=" << i_am_dead << endl; } | |
bool i_am_dead; | |
}; | |
template <typename Tc, typename T> | |
void push1 ( Tc & c, T t ) | |
{ | |
c.push_back(move(t)); | |
} | |
template <typename Tc, typename T> | |
void push2 ( Tc & c, const T & t ) | |
{ | |
c.push_back(t); | |
} | |
template <typename Tc, typename T> | |
void push3 ( Tc & c, T && t ) | |
{ | |
c.push_back(forward<T>(t)); | |
} | |
Report f(int bla) { | |
return Report(); | |
} | |
int main(int argc, const char * argv[]) | |
{ | |
cout << "push1" << endl; | |
{ | |
vector<Report> a; | |
Report b; | |
push1(a, b); | |
} | |
cout << "push2" << endl; | |
{ | |
vector<Report> a; | |
Report b; | |
push2(a, b); | |
} | |
cout << "push3" << endl; | |
{ | |
vector<Report> a; | |
Report b; | |
push3(a, b); | |
} | |
cout << "push1 with a temporary returned from f" << endl; | |
{ | |
vector<Report> a; | |
push1(a, f(123)); | |
} | |
cout << "push2 with a temporary returned from f" << endl; | |
{ | |
vector<Report> a; | |
push2(a, f(123)); | |
} | |
cout << "push3 with a temporary returned from f" << endl; | |
{ | |
vector<Report> a; | |
push3(a, f(123)); | |
} | |
} | |
/* | |
push1 | |
Report(); | |
Report(const Report&); | |
Report(&&); | |
~Report() i_am_dead=1 | |
~Report() i_am_dead=0 | |
~Report() i_am_dead=0 | |
push2 | |
Report(); | |
Report(const Report&); | |
~Report() i_am_dead=0 | |
~Report() i_am_dead=0 | |
push3 | |
Report(); | |
Report(const Report&); | |
~Report() i_am_dead=0 | |
~Report() i_am_dead=0 | |
push1 with a temporary returned from f | |
Report(); | |
Report(&&); | |
~Report() i_am_dead=1 | |
~Report() i_am_dead=0 | |
push2 with a temporary returned from f | |
Report(); | |
Report(const Report&); | |
~Report() i_am_dead=0 | |
~Report() i_am_dead=0 | |
push3 with a temporary returned from f | |
Report(); | |
Report(&&); | |
~Report() i_am_dead=1 | |
~Report() i_am_dead=0 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment