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
Post a Comment