std::unorde...imap::insert(3)
π NAME π
std::unordered_multimap::insert β std::unordered_multimap::insert. bestie, yes the name is doing a little echo thing, iykyk π. This is the std::unordered_multimap::insert(3) page from the C++ Standard Libary manual, and we're gonna get you comfy with every single overload. no skipping, periodt.
β¨ Synopsis β¨
Defined in header <unordered_map>
iterator insert( const value_type& value ); (1)
(since C++11)
iterator insert( value_type&& value ); (2)
(since C++17)
template< class P > (3)
(since C++11)
iterator insert( P&& value );
iterator insert( const_iterator hint, const value_type& value ); (4)
(since C++11)
iterator insert( const_iterator hint, value_type&& value ); (5)
(since C++17)
template< class P > (6)
(since C++11)
iterator insert( const_iterator hint, P&& value );
template< class InputIt > (7)
(since C++11)
void insert( InputIt first, InputIt last );
void insert( std::initializer_list<value_type> ilist ); (8)
(since C++11)
iterator insert( node_type&& nh ); (9)
(since C++17)
iterator insert( const_iterator hint, node_type&& nh ); (10)
(since C++17)
okay so the whole gig: this inserts element(s) into the container β¨.
1β3β insertsvalue. Overload(3)is equivalent toemplace(std::forward<P>(value))and only participates in overload resolution ifstd::is_constructible<value_type, P&&>::value == true.4β6β insertsvalue, usinghintas a non-binding suggestion to where the search should start. Overload(6)is equivalent toemplace_hint(hint, std::forward<P>(value))and only participates in overload resolution ifstd::is_constructible<value_type, P&&>::value == true.7β inserts elements from range[first, last). If[first, last)is not a valid range, orfirstand/orlastare iterators into*this, the behavior is undefined. that's UB, bestie β do not.8β inserts elements from initializer listilist.9β ifnhis an empty node handle, does nothing. Otherwise, inserts the element owned bynhinto the container and returns an iterator pointing at the inserted element. The behavior is undefined ifnhis not empty andget_allocator() != nh.get_allocator().10β 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().hintis used as a non-binding suggestion to where the search should start. The behavior is undefined ifnhis not empty andget_allocator() != nh.get_allocator().
β οΈ If after the operation the new number of elements is greater than oldmax_load_factor() * bucket_count()a rehashing takes place. If rehashing occurs (due to the insertion), all iterators are invalidated. Otherwise (no rehashing), iterators are not 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 πΈ
hintβ iterator, used as a suggestion as to where to insert the contentvalueβ 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β6β an iterator to the inserted element.7,8β(none).9,10β end iterator ifnhwas empty, iterator pointing to the inserted element otherwise.
π Exceptions π
1β6β if an exception is thrown for any reason, these functions have no effect (strong exception safety guarantee).7,8β no exception safety guarantee.9,10β if an exception is thrown for any reason, these functions have no effect (strong exception safety guarantee).
β±οΈ Complexity β±οΈ
1β6β average case:O(1), worst caseO(size()).7,8β average case:O(N), whereNis the number of elements to insert. Worst case:O(N * size() + N).9,10β average case:O(1), worst caseO(size()).
π§ͺ Example π§ͺ
This section is incomplete Reason: no example
π Defect reports π
the following behavior-changing defect reports were applied retroactively to previously published C++ standards β yes, the committee came back later like βactuallyβ¦β and honestly, iconic.
- DR
LWG 2005β applied toC++11. Behavior as published: overloads (3,6) would only participate in overload resolution ifPis implicitly convertible tovalue_type. Correct behavior: only participates ifvalue_typeis constructible fromP&&.
π See also π
emplaceβ constructs element in-place (public member function)emplace_hintβ constructs elements in-place using a hint (public member function)inserterβ creates astd::insert_iteratorof type inferred from the argument (function template)
π·οΈ Category π·οΈ
* Todo no example
okay bestie, that's the whole page π«Ά source/version + date: http://cppreference.com Β· 2024.06.10 πβ¨
π¦ 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