std::vector<T,Allocator>::assign_range - cppreference.com (original) (raw)
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.
[edit] Parameters
Notes
| Feature-test macro | Value | Std | Feature |
|---|---|---|---|
| __cpp_lib_containers_ranges | 202202L | (C++23) | Ranges-aware construction and insertion |
[edit] Example
#include #include #include #include int main() { const auto source = std::list{2, 7, 1}; auto destination = std::vector{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)); }
[edit] See also
| | inserts a range of elements (public member function) | | --------------------------------------------------------------- | | | adds a range of elements to the end (public member function) | | | assigns values to the container (public member function) | | | assigns values to the container (public member function) |