After asking dummy questions yesterday, experimenting, and reading quite a bunch about emplace_back
over push_back
, I'm still not really sure which one I should use "by default", meaning most of the time.
As was pointed out in the answer to popular question "Why would I ever use push_back instead of emplace_back?" and in other articles, the first impression people got after introducing emplace_back
that "it can do anything that push_back (insert) can do and sometimes can do it better" is wrong.
So far, I have an impression that in cases where I'm using move semantics (or if I need to make I copy), where I can't benefit from the in-place object creation, and when I don't need the return value, it would be safer to use push_back
not to run into troubles I can get with explicit constructor described in the links, and probably some more.
Simply saying, if I'm not using new features that emplace_back
has and push_back
/insert
doesn't, I better stick with the push_back
/insert
.
Am I correct, or am I again missing something?