emplace vs push c++ code example

Example: 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().

Tags:

Cpp Example