In C ++ 11, emplace_back() usually preferable (in terms of efficiency) to push_back() , since it allows you to build in place , but does this still occur when using push_back(std::move()) constructed object?
For example, emplace_back() is still preferable in the following cases:
std::string mystring("hello world"); std::vector<std::string> myvector; myvector.emplace_back(mystring); myvector.push_back(std::move(mystring));
Also, is there an advantage in the above example instead:
myvector.emplace_back(std::move(mystring));
or is this movement completely redundant or has no effect?
c ++ 11 move-semantics push-back emplace
Riot Nov 11 '14 at 8:41 2014-11-11 08:41
source share