...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Insert an element or assign to the current element if the key already exists.
template< class M>std::pair
<object::iterator
, bool > insert_or_assign(string_view
key, M&& m);
If the key equivalent to key
already exists in the container, assigns std::forward<M>(m)
to the mapped_type
corresponding to the key. Otherwise, inserts the new value at the end as
if by insert, constructing it from value_type(key, std::forward<M>(m))
.
If the insertion occurs and results in a rehashing of the container, all
iterators and references are invalidated. Otherwise, they are not affected.
Rehashing occurs only if the new number of elements is greater than capacity()
.
Amortized constant on average, worst case linear in size()
.
Strong guarantee. Calls to memory_resource::allocate
may throw.
A std::pair
where first
is an iterator to the existing or inserted element, and second
is true
if the insertion took
place or false
if the assignment
took place.
Name |
Description |
---|---|
|
The key used for lookup and insertion |
|
The value to insert or assign |
Type |
Thrown On |
---|---|
boost::system::system_error |
if key is too long. |