std::flat_multimap<Key,T,Compare,KeyContainer,MappedContainer>::emplace - cppreference.com (original) (raw)
| template< class... Args >iterator emplace( Args&&... args ); | | (since C++23) (constexpr since C++26) | | ------------------------------------------------------------- | | ------------------------------------- |
Inserts a new element into the container constructed in-place with the given args.
Initializes an object t of type std::pair<key_type, mapped_type> with std::forward<Args>(args)...; if the map already contains an element whose key is equivalent to t.first, *this is unchanged. Otherwise, equivalent to:
auto key_it = ranges::upper_bound(c.keys, t.first, compare); auto value_it = c.values.begin() + std::distance(c.keys.begin(), key_it); c.keys.insert(key_it, std::move(t.first)); c.values.insert(value_it, std::move(t.second));
This overload participates in overload resolution only if std::is_constructible_v<std::pair<key_type, mapped_type>, Args...> is true.
If value_type is not EmplaceConstructible into flat_multimap from args, the behavior is undefined.
Contents
[edit] Parameters
| args | - | arguments to forward to the constructor of the element |
|---|
[edit] Return value
An iterator to the inserted element.
[edit] Exceptions
If an exception is thrown for any reason, this function has no effect (strong exception safety guarantee).
[edit] Complexity
Linear in the size of the container
[edit] Notes
Careful use of emplace allows the new element to be constructed while avoiding unnecessary copy or move operations.
[edit] Example
Output:
a => a b => abcd c => cccccccccc d => ddd d => DDD