(C++17) | ||||
| Sequence | ||||
(C++11) | ||||
(C++26) | ||||
(C++26) | ||||
(C++11) | ||||
| Associative | ||||
| Unordered associative | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
(C++11) | ||||
| Adaptors | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
(C++23) | ||||
| Views | ||||
(C++20) | ||||
(C++23) | ||||
| Tables | ||||
| Iterator invalidation | ||||
| Member function table | ||||
| Non-member function table |
| Member functions | |||||||
| Non-member functions | |||||||
| |||||||
| Deduction guides(C++17) | |||||||
iterator insert(const value_type& value); | (1) | |
iterator insert( value_type&& value); | (2) | (since C++11) |
| (3) | ||
iterator insert( iterator pos,const value_type& value); | (until C++11) | |
iterator insert( const_iterator pos,const value_type& value); | (since C++11) | |
iterator insert( const_iterator pos, value_type&& value); | (4) | (since C++11) |
template<class InputIt> void insert( InputIt first, InputIt last); | (5) | |
void insert(std::initializer_list<value_type> ilist); | (6) | (since C++11) |
iterator insert( node_type&& nh); | (7) | (since C++17) |
iterator insert( const_iterator pos, node_type&& nh); | (8) | (since C++17) |
Inserts element(s) into the container. The order of the remaining equivalent elements is preserved.
[first, last).No iterators or references are invalidated.If the insertion is successful, pointers and references to the element obtained while it is held in the node handle are invalidated, and pointers and references obtained to that element before it was extracted become valid.(since C++17)
Contents |
| pos | - | iterator to the position before which the new element will be inserted |
| value | - | element value to insert |
| first, last | - | the pair of iterators defining the sourcerange of elements to insert |
| ilist | - | initializer list to insert the values from |
| nh | - | a compatiblenode handle |
| Type requirements | ||
-InputIt must meet the requirements ofLegacyInputIterator. | ||
O(log(size()))O(log(size())) otherwise.O(N·log(size() + N)), whereN is the number of elements to insert.| This section is incomplete Reason: no example |
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 233 | C++98 | pos was just a hint, it could be totally ignored | the insertion is required to be as close as possible to the position just prior topos |
| LWG 264 | C++98 | the complexity of overload(5) was required to be linear if the range [first, last) is sorted according toCompare | removed the linear requirement in this special case |
| LWG 371 | C++98 | the order of equivalent elements was not guaranteed to be preserved | required to be preserved |
(C++11) | constructs element in-place (public member function)[edit] |
(C++11) | constructs elements in-place using a hint (public member function)[edit] |
| creates astd::insert_iterator of type inferred from the argument (function template)[edit] |