object::insert
Insert elements.
Synopsis
template<
class P>
std::pair< object::iterator, bool >
insert(
P&& p); (1)
template<
class InputIt>
void
insert(
InputIt first,
InputIt last); (2)
void
insert(
std::initializer_list< std::pair< string_view, value_ref > > init); (3)
Description
-
(1) inserts a new element constructed as if via
value_type( std::forward<P>(p) ). -
(2) the elements in the range
[first, last)are inserted one at a time, in order. -
(3) the elements in the initializer list are inserted one at a time, in order.
Any element with key that is a duplicate of a key already present in container will be skipped. This also means, that if there are two keys within the inserted range that are equal to each other, only the first will be inserted.
If an insertion would result in the new number of elements exceeding capacity(), a reallocation and a rehashing occur. In that case all iterators and references are invalidated. Otherwise, they are not affected.
Preconditions
first and last are not iterators into *this. first and last form a valid range.
Constraints
std::is_constructible_v<value_type, P>
std::is_constructible_v<value_type, std::iterator_traits<InputIt>::reference>
Complexity
-
(1) constant on average, worst case linear in
size(). -
(2) linear in
std::distance(first, last). -
(3) linear in
init.size().
Exception Safety
-
(1) strong guarantee.
-
(2) strong guarantee if
InputItsatisfies LegacyForwardIterator, basic guarantee otherwise. -
(3) basic guarantee.
Calls to memory_resource::allocate may throw.
Template Parameters
| Type | Description |
|---|---|
|
a type satisfying the requirements of LegacyInputIterator. |
Return Value
(1) returns 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 otherwise. (2) returns void.
Parameters
| Name | Description |
|---|---|
|
The value to insert. |
|
An input iterator pointing to the first element to insert, or pointing to the end of the range. |
|
An input iterator pointing to the end of the range. |
|
The initializer list to insert. |
Exceptions
| Type | Thrown On |
|---|---|
|
The size of a key would exceed |
|
|