std::multiset::insert(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

🌸 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) β€” Inserts value. If the container has elements with equivalent key, inserts at the upper bound of that range.
  • 3,4) β€” Inserts value in the position as close as possible to the position just prior to pos.
  • 5) β€” Inserts elements from range [first, last).
  • 6) β€” Inserts elements from initializer list ilist.
  • 7) β€” If nh is an empty node handle, does nothing. Otherwise, inserts the element owned by nh into the container and returns an iterator pointing at the inserted element. If a range containing elements with keys equivalent to nh.key() exists in the container, the element is inserted at the end of that range. The behavior is undefined if nh is not empty and get_allocator() != nh.get_allocator(). ⚠️ undefined behavior warning, bestie ⚠️
  • 8) β€” If nh is an empty node handle, does nothing and returns the end iterator. Otherwise, inserts the element owned by nh into the container, and returns the iterator pointing to the element with key equivalent to nh.key(). The element is inserted as close as possible to the position just prior to pos. The behavior is undefined if nh is not empty and get_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 inserted
  • value β€” element value to insert
  • first, last β€” range of elements to insert
  • ilist β€” initializer list to insert the values from
  • nh β€” a compatible node handle

πŸŽ€ Type requirements πŸŽ€

  • InputIt must meet the requirements of LegacyInputIterator.

πŸ’– Return value πŸ’–

  • 1-4) β€” An iterator to the inserted element.
  • 5,6) β€” (none)
  • 7,8) β€” End iterator if nh was 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 before pos, O(log(size())) otherwise.
  • 5,6) β€” O(NΒ·log(size() + N)), where N is 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: pos was 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 to pos.
  • 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 to Compare. 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 a std::insert_iterator of 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