Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualBrother Bob

Posted 03 February 2014 - 08:42 AM

 

Correct me if I'm wrong, but there's little point in calling std::move on an lvalue (as is the case in your code).
 
It'd make more sense like this:


vector<Test> v;
v.push_back(std::move(Test()));

You are wrong. In your example you don't even need the std::move because 'Test()' is an xvalue as an expiring temporary. The whole point of std::move it to allow it on what would usually be lvalues.

 

Also, if the intention is to construct a temporary object just to pass it to push_back, you should instead use emplace_back to construct it in-place inside the vector and skip the temporary object entirely.


#1Brother Bob

Posted 03 February 2014 - 08:41 AM

 

Correct me if I'm wrong, but there's little point in calling std::move on an lvalue (as is the case in your code).
 
It'd make more sense like this:


vector<Test> v;
v.push_back(std::move(Test()));

You are wrong. In your example you don't even need the std::move because 'Test()' is an xvalue as an expiring temporary. The whole point of std::move it to allow it on what would usually be lvalues.

 

Also, if the intention is to construct a temporary object just to pass it to push_back, you should instead emplace_back to construct it in-place inside the vector and skip the temporary object entirely.


PARTNERS