Saturday, 15 March 2014

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


Based on the answers, I know that it's definitely std :: make_unique < / Code> to emplace_back (new x) directly.

He said, like calling it

  my_vector.push_back (std :: McQueen & lt; Foo & gt; ("constructor", "args") );  

or

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

Is that, when using a std :: unique_ptr when using push_back or emplace_back Should std :: make_unique be added?

==== Edit ====

Why else? C: & lt; - (small smile)

It does not matter, you already have a Unique_ptr & lt; Foo & gt; Preview (call result make_unique ) will therefore call both push_back and emplace_back vector .


No comments:

Post a Comment