std::multiset::insert(3)
πΈ std::multiset::insert(3) πΈ
okay bestie, welcome to the std::multiset::insert(3) page from the C++ Standard Libary manual β¨ this is C++ Standard Library content, and this page is lowkey overload city. No cap, every spicy detail is right here, and Iβm not skipping a single one π
β¨ NAME β¨
std::multiset::insert β std::multiset::insert π«Ά (yes, thatβs literally the name, and weβre keeping it exactly like that π)
β¨ Synopsis β¨
iterator insert( const value_type& value ); (1)
iterator insert( value_type&& value ); (2) (since C++11)
iterator insert( iterator pos, const value_type& value ); (3) (until C++11)
iterator insert( const_iterator pos, const value_type& value ); (3) (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)
iykyk, the overload numbers are doing their little chaotic dance, but every signature and annotation is here π¦
π DESCRIPTION π
Inserts element(s) into the container. The order of the remaining equivalent elements is preserved. π«Ά
1,2)β Insertsvalue. If the container has elements with equivalent key, inserts at the upper bound of that range.3,4)β Insertsvaluein the position as close as possible to the position just prior topos.5)β Inserts elements from range[first, last).6)β Inserts elements from initializer listilist.7)β Ifnhis an empty node handle, does nothing. Otherwise, inserts the element owned bynhinto the container and returns an iterator pointing at the inserted element. If a range containing elements with keys equivalent tonh.key()exists in the container, the element is inserted at the end of that range. The behavior is undefined ifnhis not empty andget_allocator() != nh.get_allocator(). β οΈ undefined behavior warning, bestie β οΈ8)β Ifnhis an empty node handle, does nothing and returns the end iterator. Otherwise, inserts the element owned bynhinto the container, and returns the iterator pointing to the element with key equivalent tonh.key(). The element is inserted as close as possible to the position just prior topos. The behavior is undefined ifnhis not empty andget_allocator() != nh.get_allocator(). β οΈ same undefined-behavior caveat, do not ignore β οΈ
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)
πΈ Parameters πΈ
posβ iterator to the position before which the new element will be insertedvalueβ element value to insertfirst,lastβ range of elements to insertilistβ initializer list to insert the values fromnhβ a compatible node handle
π Type requirements π
InputItmust meet the requirements ofLegacyInputIterator.
π Return value π
1-4)β An iterator to the inserted element.5,6)β (none)7,8)β End iterator ifnhwas empty, iterator pointing to the inserted element otherwise.
π₯ Exceptions π₯
1-4,7,8)β If an exception is thrown by any operation, the insertion has no effect.5,6)β No exception safety guarantee.
π¦ Complexity π¦
1,2,7)βO(log(size()))3,4,8)β Amortized constant if the insertion happens in the position just beforepos,O(log(size()))otherwise.5,6)βO(NΒ·log(size() + N)), whereNis the number of elements to insert.
π Example π
This section is incomplete Reason: no example
not me staring at an empty example section π
π Defect reports π
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- LWG 233 β Applied to: C++98. Behavior as published:
poswas just a hint, it could be totally ignored. Correct behavior: the insertion is required to be as close as possible to the position just prior topos. - LWG 264 β Applied to: C++98. Behavior as published: the complexity of overload (5) was required to be linear if the range
[first, last)is sorted according toCompare. Correct behavior: removed the linear requirement in this special case. - LWG 371 β Applied to: C++98. Behavior as published: the order of equivalent elements was not guaranteed to be preserved. Correct behavior: required to be preserved.
π See also π
emplaceβ constructs element in-place (C++11) (public member function)emplace_hintβ constructs elements in-place using a hint (C++11) (public member function)inserterβ creates astd::insert_iteratorof type inferred from the argument (function template)
π Category π
Todo no example
π source/version/date: http://cppreference.com Β· 2024.06.10 Β· std::multiset::insert(3) π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms