std::hive<T,Allocator>::insert
From cppreference.com
iterator insert( const T& value );
|
(1) | (since C++26) |
iterator insert( T&& value );
|
(2) | (since C++26) |
iterator insert( const_iterator hint, const T& value );
|
(3) | (since C++26) |
iterator insert( const_iterator hint, T&& value );
|
(4) | (since C++26) |
void insert( std::initializer_list<T> ilist );
|
(5) | (since C++26) |
template< class InputIter >
void insert( InputIter first, InputIter last );
|
(6) | (since C++26) |
void insert( size_type count, const T& value );
|
(7) | (since C++26) |
Inserts elements into the hive at unspecified location.
1,3) Inserts a copy of
value.2,4) Inserts
value, possibly using move semantics as if by emplace(std::forward<decltype(x)>(x));.5) Inserts elements from initializer list
ilist.6) Inserts the elements from range
[first, last). Equivalent toinsert_range(ranges::subrange(first, last));.7) Inserts
count copies of the value.5,6) Each iterator in the input range is dereferenced exactly once.
5,6,7) Exactly one object of type
T is constructed for each inserted element.If an element is inserted, the end() iterator is invalidated.
Parameters
| value | - | element value to insert |
| hint | - | ignored (exists only for compatibility) |
| ilist | - | initializer list to insert the values from |
| first, last | - | the pair of iterators defining the range of elements to insert (cannot be iterators into container for which insert is called) |
| count | - | number of elements to insert |
| Type requirements | ||
-InputIter must meet the requirements of LegacyInputIterator in order to use overload (6).
| ||
-T must meet the requirements of EmplaceConstructible in order to use overloads (1-6).
| ||
-T must meet the requirements of CopyInsertable in order to use overload (7).
| ||
Return value
1-4) An iterator that points to the new element.
Complexity
1-4) Constant.
5,6) Linear in the number of inserted elements.
7) Linear in
count.Example
Run this code
#include <hive>
#include <initializer_list>
#include <print>
int main()
{
std::hive<int> colony(3, 10);
std::println("1. {}", colony);
colony.insert(20); // overload (1)
std::println("2. {}", colony);
colony.insert({30, 31, 32}); // overload (5)
std::println("3. {}", colony);
const auto list = {40, 41, 42};
colony.insert(list.begin(), list.end()); // overload (6)
std::println("4. {}", colony);
colony.insert(4, 50); // overload (7)
std::println("5. {}", colony);
}
Possible output:
1. [10, 10, 10]
2. [10, 10, 10, 20]
3. [10, 10, 10, 20, 30, 31, 32]
4. [10, 10, 10, 20, 30, 31, 32, 40, 41, 42]
5. [10, 10, 10, 20, 30, 31, 32, 40, 41, 42, 50, 50, 50, 50]
See also
| inserts a range of elements (public member function) | |
| constructs element in-place (public member function) |