In C++11 emplace_back()
is generally preferred (in terms of efficiency) to push_back()
as it allows in-place construction, but is this still the case when using push_back(std::move())
with an already-constructed object?
For instance, is emplace_back()
still preferred in cases like the following?
std::string mystring("hello world");
std::vector<std::string> myvector;
myvector.emplace_back(mystring);
myvector.push_back(std::move(mystring));
// (of course assuming we don't care about using the value of mystring after)
Additionally, is there any benefit in the above example to instead doing:
myvector.emplace_back(std::move(mystring));
or is the move here entirely redundant, or has no effect?