#include <vector> using namespace std; struct A { A(const vector<int>&) {} A(vector<int>&&) {} }; A f() { vector<int> coll; return A{ coll }; // Which constructor of A will be called as per C++11? } int main() { f(); }
Is coll a xvalue in return A{ coll }; ?
coll
xvalue
return A{ coll };
Is a C ++ 11 A(vector<int>&&) warranty provided on returning f ?
A(vector<int>&&)
f
C ++ 11 does not allow moving coll . It allows implicit moves in return when you execute return <identifier> , where <identifier> is the name of a local variable. Any expression that is more complex than this will not be implicitly moved.
return
return <identifier>
<identifier>
And expressions more complex than this will not undergo any form.