...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Insert elements.
template< class P> std::pair< iterator, bool > insert( P&& p);
Inserts p
if this->contains(value_type(p).key())
is false
. value_type
must be constructible
from p
. 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()
.
std::is_constructible_v<value_type, P>
Average case amortized constant, worst case linear in size()
.
Strong guarantee. Calls to memory_resource::allocate
may throw.
Name |
Description |
---|---|
|
The value to insert. |
Type |
Thrown On |
---|---|
|
key is too long. |
|
|
A pair where first
is
an iterator to the existing or inserted element, and second
is true
if the insertion
took place or false
otherwise.