"". , ( ) . , std::string "", , - , as-if. , , - :
struct foo {
foo(foo const &f) { std::cout << "copy ctor\n"; }
foo(foo &&f) { std::cout << "move ctor\n"; }
};
foo outer;
{
foo inner;
outer = inner;
}
... , "copy ctor", "move ctor". - , , , , .
, : , , . , . , , , , , - .
, , - , .
(N4659, § [class.copy.elision]/3):
- :
- return (9.6.3) (, ) id-, , -- - ,
[...]
, rvalue. , rvalue (, cv-qualified), , .
(y) return id-, , , .
, , X y. X ( ) , y . , , "" . , , y rvalue, , X ctor .
, X - :
struct X
{
X(Y &&y);
X(Y const &y);
Y y_;
}
... , - y lvalue, rvalue, X(Y &&y) X, , .. ( y lvalue, , lvalue).