0

I understand that with emplace_back you provide it constructor arguments, and with push_back you provide it with a copy from which to copy. However when passing the type that the element type of the vector it seems to me that they might be the same, because emplace_back will move-construct in place with the copy you provide, which is what push_back does, right?

Unless push_back default constructs a new object, and then uses operator= to move the argument. In that case they would be different.

Evg
  • 25,259
  • 5
  • 41
  • 83
Zebrafish
  • 11,682
  • 3
  • 43
  • 119
  • 2
    [this answer](https://stackoverflow.com/a/4303834/12257925) answers your question (if I understood it right). If i didn't, don't hesitate to let me know – DiantArts Apr 28 '22 at 05:47
  • 1
    In libstdc++ [implementation](https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/stl_vector.h#L1293-L1294), `push_back()` overload that takes `value_type&&` dispatches the call to `emplace_back()`, so there is no difference at all. – Evg Apr 28 '22 at 05:55

0 Answers0