From cppreference.com
template</*container-compatible-range*/<T>R>voidassign_range(R&&rg);(since C++23)Replaces elements in the container with a copy of each element in rg.
All iterators (including the
iterator) and all references to the elements are invalidated.
Each iterator in the range rg is dereferenced exactly once.
The behavior is undefined if rg overlaps with the container.
Parameters
rg - an
with reference type convertible to the element type of the container Type requirements -std::assignable_from<T&,ranges::range_reference_t<R>> must be modeled. Otherwise, the program is ill-formed. -T must be
into the container from *ranges::begin(rg). Otherwise, the behavior is undefined. Notes
macro ValueStdFeature
(C++23)
construction and insertion Example
Run this code
#include<algorithm>#include<cassert>#include<forward_list>#include<list>intmain(){constautosource=std::list{2,7,1};autodestination=std::forward_list{3,1,4};#ifdef __cpp_lib_containers_rangesdestination.assign_range(source);#elsedestination.assign(source.cbegin(),source.cend());#endifassert(std::ranges::equal(source,destination));}See also
(C++23)
inserts a range of elements after an element
(public member function)(C++23)
adds a range of elements to the beginning
(public member function)assigns values to the container
(public member function)assigns values to the container
(public member function)