Answers for "emplace vs push c++"

C++
0

emplace vs push c++

push() adds a copy of an already constructed object into the queue as a 
parameter, it takes an object of the queue's element type.

emplace() constructs a new object in-place at the end of the queue. It takes 
as parameters the parameters that the queue's element types constructor takes.

If your usage pattern is one where you create a new object and add it to the
container, you shortcut a few steps (creation of a temporary object and copying
it) by using emplace().
Posted by: Guest on May-12-2021

Browse Popular Code Answers by Language