Appends a new element to the end of the container. The element is constructed in-place, i.e. no copy or move operations are performed. The constructor of the element is called with exactly the same arguments that are supplied to the function.

The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions.

If the new size() is greater than capacity(), all iterators and references are invalidated. Otherwise no iterators and references are invalidated.

The following code uses emplace_back to append an object of type President to a std::vector. It demonstrates how emplace_back forwards parameters to the President constructor and shows how using emplace_back avoids the extra copy or move operation required when using push_back.

The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions.

emplace_back:
I am being constructed.
push_back:
I am being constructed.
I am being moved.
Contents:
Nelson Mandela was elected president of South Africa in 1994.
Franklin Delano Roosevelt was re-elected president of the USA in 1936.