std::deque<T,Allocator>::assign_range
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Containers library
(C++17)
(C++11)
(C++26)
(C++26)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++23)
(C++23)
(C++23)
(C++23)
(C++20)
(C++23)
Tables
std::deque
Non-member functions
Deduction guides (C++17)
deque::assign_range
(C++23)
(C++11)
(C++11)
(C++11)
(C++11)
(DR*)
(C++23)
(C++11)
(C++23)
(C++11)
(C++23)
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)
template< container-compatible-range <T> R >
void assign_range( R&& rg );
(since C++23) void assign_range( R&& rg );
(constexpr since C++26)
Replaces elements in the container with a copy of each element in rg.
All iterators (including the end()
iterator) and all references to the elements are invalidated.
Each iterator in the range rg is dereferenced exactly once.
If rg overlaps with *this, the behavior is undefined.
Contents
[edit] Parameters
rg
-
an
input_range
with reference type convertible to the element type of the container
Type requirements
-If std::assignable_from <T&, ranges::range_reference_t <R>> is not modeled, the program is ill-formed.
Notes
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | Ranges-aware construction and insertion |
[edit] Example
Run this code
#include <algorithm> #include <cassert> #include <deque> #include <list> int main() { const auto source = std::list {2, 7, 1}; auto destination = std::deque {3, 1, 4}; #ifdef __cpp_lib_containers_ranges destination.assign_range(source); #else destination.assign(source.cbegin(), source.cend()); #endif assert (std::ranges::equal (source, destination)); }