Jump to content

C++ Language/Std/Stl/CollectionClasses/SequenceCollections/Vector/InsertingItems

From Wikibooks, open books for an open world

An inserted item does not need to have the exact same item-type as the vector, as long as it can be coerced into the vector's item-type. If there will be coercion, then insertion by emplace() will be faster than insert() because emplace() directly uses a single-parameter-cast-constructor instead of copy-constructing from a compiler-temporary that holds the coerced-value.

To insert as the vector's last item, use emplace_back() or push_back().

Additional information about inserting items into a vector (includes interactive examples)