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.
There are no guarantees on the relative order of elements with equivalent keys.
The relative ordering of elements with equivalent keys is preserved, and newly inserted elements follow those with equivalent keys already in the container.
- Arguments forwarded to construct the new element (of type pair<const key_type, mapped_type>).
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.