Namespaces
Variants
Views
Actions

std::inplace_vector<T,N>::insert

From cppreference.com
< cpp‎ | container‎ | inplace vector
Revision as of 14:07, 27 August 2024 by Space Mission (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
 
 
 
 
constexpr iterator insert( const_iterator pos, const T& value );
(1) (since C++26)
constexpr iterator insert( const_iterator pos, T&& value );
(2) (since C++26)
constexpr iterator insert( const_iterator pos, size_type count,
                           const T& value );
(3) (since C++26)
template< class InputIt >
constexpr iterator insert( const_iterator pos, InputIt first, InputIt last );
(4) (since C++26)
constexpr iterator insert( const_iterator pos, std::initializer_list<T> ilist );
(5) (since C++26)

Inserts elements at the specified location in the container.

1) Inserts a copy of value before pos.
2) Inserts value before pos, possibly using move semantics.
3) Inserts count copies of the value before pos.
4) Inserts elements from range [firstlast) before pos. This overload participates in overload resolution only if InputIt qualifies as LegacyInputIterator, to avoid ambiguity with the overload (3).
Each iterator in [firstlast) is dereferenced once.
If first and last are iterators into *this, the behavior is undefined.
5) Inserts elements from initializer list ilist before pos. Equivalent to: insert(pos, ilist.begin(), ilist.end());.


Contents

Parameters

pos - iterator before which the content will be inserted (pos may be the end() iterator)
value - element value to insert
count - number of elements to insert
first, last - the range of elements to insert
ilist - std::initializer_list to insert the values from
Type requirements
-
T must meet the requirements of CopyInsertable in order to use overload (1).
-
T must meet the requirements of MoveInsertable in order to use overload (2).
-
T must meet the requirements of CopyAssignable and CopyInsertable in order to use overload (3).
-
T must meet the requirements of EmplaceConstructible in order to use overloads (4,5).

Return value

1,2) Iterator pointing to the inserted value.
3) Iterator pointing to the first element inserted, or pos if count == 0.
4) Iterator pointing to the first element inserted, or pos if first == last.
5) Iterator pointing to the first element inserted, or pos if ilist is empty.

Complexity

Linear in the distance between pos and end() of the container.

Exceptions

Example

See also

constructs element in-place
(public member function) [edit]
inserts a range of elements
(public member function) [edit]