public member function
template <class... Args> iterator emplace (Args&&... args);
Construct and insert element
Inserts a new element in the multimap. This new element is constructed in place using args as the arguments for the construction of a value_type (which is an object of a pair type).
This effectively increases the container size by one.
Internally, multimap containers keep all their elements sorted by key following the criterion specified by its comparison object. The element is always inserted in its respective position following this ordering.
The element is constructed in-place by calling allocator_traits::construct with args forwarded.
A similar member function exists, insert, which either copies or moves existing objects into the container.
The relative ordering of elements with equivalent keys is preserved, and newly inserted elements follow those with equivalent keys already in the container.
Arguments used to construct a new object of the mapped type for the inserted element.
Arguments forwarded to construct the new element (of type
pair<const key_type, mapped_type>
This can be one of:
- Two arguments: one for the key
, the other for the mapped value
- A single argument of a
type with a value for the key
as first member, and a value for the mapped value
as first argument, and two additional arguments with tuples
to be forwarded as arguments for the key value
and for the mapped value
for more info.
An iterator to the newly inserted element.
Member type iterator is a bidirectional iterator type that points to an element.
int main ()
std::cout << "mymultimap contains:";
for (auto& x: mymultimap)
std::cout << " [" << x.first << ':' << x.second << ']';
std::cout << '\n';
mymultimap contains: [apple:1.5] [apple:1.4] [coffee:2.1]
Logarithmic in the container size.
The container is modified.
Concurrently accessing existing elements is safe, although iterating ranges in the container is not.
Strong guarantee: if an exception is thrown, there are no changes in the container.
If allocator_traits::construct is not supported with the appropriate arguments, it causes undefined behavior.