c++ - push_back or emplace_back with std::make_unique -


based on answers in these questions here, know preferred use c++14's std::make_unique emplace_back(new x) directly.

that said, preferred call

my_vector.push_back(std::make_unique<foo>("constructor", "args")); 

or

my_vector.emplace_back(std::make_unique<foo>("constructor", "args")); 

that is, should use push_back or emplace_back when adding std::unique_ptr constructed std::make_unique?

==== edit ====

and why? c: <-- (tiny smile)

it doesn't make difference, have unique_ptr<foo> prvalue (the result of call make_unique) both push_back , emplace_back call unique_ptr move constructor when constructing element appended vector.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -