c++ - Do the new C++11 emplace methods make the previous C++98/03 push_back/insert methods obsolete? -


this question has answer here:

does still make sense in c++11 use vector::push_back() instead of vector::emplace_back(), , map::insert() instead of map::emplace()?

my understanding new modern c++11 emplace-methods construct objects in place given arguments (perfectly forwarded constructors), save copy , move operations, should more efficient old c++98/03 counterparts.

am missing that?

is safe discourage use of old-style methods?

as say, emplace_back meant construct objects. if have object , want copy or move inside container? why should call emplace_back create new instance, if can move existing object new instance?

both alternatives can useful, different purposes. emplace_back might able same push_back same performance, it's still cleaner show intent in code.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -