std::forward_list<T,Allocator>:: insert_range_after
From cppreference.net
<
cpp
|
container
|
forward list
|
template
<
container-compatible-range
<
T
>
R
>
iterator insert_range_after ( const_iterator pos, R && rg ) ; |
(since C++23)
(constexpr since C++26) |
|
Inserts copies of elements in the range rg after pos . Each iterator in the range rg is dereferenced exactly once.
If any of the following conditions is satisfied, the behavior is undefined:
-
Tis not EmplaceConstructible intoforward_listfrom * ranges:: begin ( rg ) . -
pos
is not in the range
[before_begin(),end()). - rg and * this overlap.
No iterators or references become invalidated.
Contents |
Parameters
| pos | - | an iterator after which the content will be inserted |
| rg | - |
a
container compatible range
, that is, an
input_range
whose elements are convertible to
T
|
Return value
An iterator to the last inserted element, or pos if rg is empty.
Complexity
Linear in size of rg .
Notes
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-aware construction and insertion |
Example
Run this code
#include <algorithm> #include <cassert> #include <forward_list> #include <iterator> #include <vector> int main() { auto container = std::forward_list{1, 2, 3, 4}; auto pos = std::next(container.cbegin()); assert(*pos == 2); const auto rg = std::vector{-1, -2, -3}; #ifdef __cpp_lib_containers_ranges container.insert_range_after(pos, rg); #else container.insert_after(pos, rg.cbegin(), rg.cend()); #endif assert(std::ranges::equal(container, std::vector{1, 2, -1, -2, -3, 3, 4})); }
See also
|
(C++23)
|
adds a range of elements to the beginning
(public member function) |
|
inserts elements after an element
(public member function) |
|
|
constructs elements in-place after an element
(public member function) |