📜  emplace vs push c++ 代码示例

📅  最后修改于: 2022-03-11 14:44:54.624000             🧑  作者: Mango

代码示例1
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().