C++11 vectors have the new function emplace_back
. Unlike push_back
, which relies on compiler optimizations to avoid copies, emplace_back
uses perfect forwarding to send the arguments directly to the constructor to create an object in-place. It seems to me that emplace_back
does everything push_back
can do, but some of the time it will do it better (but never worse).
What reason do I have to use push_back
?