std::flat_multimap::insert(3)
π NAME π
std::flat_multimap::insert β literally std::flat_multimap::insert, bestie. This is the std::flat_multimap::insert(3) page from the C++ Standard Libary manual (yes, that's the spelling on the page, don't come for me π), and it's giving full insert-overload lore.
β¨ Synopsis β¨
iterator insert( const value_type& value ); (1)
(since C++23)
iterator insert( value_type&& value ); (2)
(since C++23)
iterator insert( const_iterator pos, const value_type& value ); (3)
(since C++23)
iterator insert( const_iterator pos, value_type&& value ); (4)
(since C++23)
template< class P > (5)
(since C++23)
iterator insert( P&& x );
template< class P > (6)
(since C++23)
iterator insert( const_iterator pos, P&& x );
template< class InputIt > (7)
(since C++23)
void insert( InputIt first, InputIt last );
template< class InputIt >
void insert( std::sorted_equivalent_t, InputIt first, InputIt (8)
(since C++23)
last );
void insert( std::initializer_list<key_type> ilist ); (9)
(since C++23)
void insert( std::sorted_equivalent_t s,
(10) (since C++23)
std::initializer_list<key_type> ilist );
π«Ά okay so what does it actually do π«Ά
Inserts element(s) into the container. Groundbreaking, I know. Here's the tea, overload by overload:
- Inserts
value. Equivalent toreturn emplace(value);. - Inserts
value. Equivalent toreturn emplace(std::move(value));. - Inserts
valuein the position as close as possible to the position just prior topos. Equivalent toreturn emplace_hint(pos, value);. - Inserts
valuein the position as close as possible to the position just prior topos. Equivalent toreturn emplace_hint(pos, std::move(value));. - Inserts
xinto*thisas if byemplace(std::forward<P>(x));. This overload participates in overload resolution only ifstd::is_constructible_v<pair<key_type, mapped_type>, P>is true. - Inserts
xinto*thisin the position as close as possible to the position just prior topos. Equivalent toreturn emplace_hint(position, std::forward<P>(x));. This overload participates in overload resolution only ifstd::is_constructible_v<pair<key_type, mapped_type>, P>is true. - Inserts elements from range
[first, last)as if performing the following operations sequentially:- Adds elements to
cas if by
- Adds elements to
for (; first != last; ++first)
{
value_type value = *first;
c.keys.insert(c.keys.end(), std::move(value.first));
c.values.insert(c.values.end(), std::move(value.second));
}
- Sorts the range of newly inserted elements with respect to
value_comp. - Merges the resulting sorted range and the sorted range of pre-existing elements into a single sorted range.
May allocate memory during the in-place merge operation.
- Inserts elements from range
[first, last)as if performing the following operations sequentially:- Adds elements to
cas if by
- Adds elements to
for (; first != last; ++first)
{
value_type value = *first;
c.keys.insert(c.keys.end(), std::move(value.first));
c.values.insert(c.values.end(), std::move(value.second));
}
- Merges the sorted range of newly added elements and the sorted range of pre-existing elements into a single sorted range.
May allocate memory during the in-place merge operation.
- Inserts elements from initializer list
ilist. Equivalent toinsert(ilist.begin(), ilist.end());. - Inserts elements from initializer list
ilist. Equivalent toinsert(s, ilist.begin(), ilist.end());.
Also, the page literally has this line: Information on iterator invalidation is copied from here.
πΈ Parameters πΈ
posβ an iterator to the position before which the new element will be inserted.valueβ an element value to insert.first,lastβ a range of elements to insert.ilistβ an initializer list to insert the values from.xβ a value of any type that can be transparently compared with a key.sβ a disambiguation tag indicating that the input sequence is sorted (with respect tovalue_comp()).
π¦ Type requirements π¦
InputItmust meet the requirements ofLegacyInputIterator.
π Return value π
- 1-6) An iterator to the inserted element.
- 7-10) (none)
π Exceptions π
- 1-6) If an exception is thrown by any operation, the insertion has no effect.
- 7-10) No exception safety guarantee. (?)
This section is incomplete Reason: double check cases 7-10
π₯ Complexity π₯
- 1-6) Linear in
size(). - 7)
N + MΒ·log(M), whereNis thesize()before the operation andMisstd::distance(first, last). - 8) Linear in
size(). - 9)
N + MΒ·log(M), whereNis thesize()before the operation andMisilist.size(). - 10) Linear in
N, whereNissize()after the operation.
π§ Example π§
This section is incomplete Reason: no example
π 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)
π Categories π
- Todo with reason
- Todo no example
okay bestie, that's the whole page π source/version: http://cppreference.com Β· date: 2024.06.10 Β· page: std::flat_multimap::insert(3) β mwah π
π¦ 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