Namespaces
Variants
Actions

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

From cppreference.com
 
 
 
std::inplace_vector
 
template< container-compatible-range <T> R >
constexpr void assign_range( R&& rg );
(since C++26)

Replaces elements in the container with a copy of each element in rg.

This section is incomplete

Each iterator in the range rg is dereferenced exactly once.

If rg overlaps with *this, the behavior is undefined.

[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.
-If T is not EmplaceConstructible into inplace_vector from *ranges::begin (rg), the behavior is undefined.

Exceptions

[edit] Example

Run this code
#include <algorithm>
#include <cassert>
#include <initializer_list>
#include <inplace_vector>
#include <iostream>
#include <new>
 
int main()
{
 const auto source = {1, 2, 3};
 std::inplace_vector <int, 4> destination{4, 5};
 destination.assign_range(source);
 assert (std::ranges::equal (destination, source));
 
 try
 {
 const auto bad = {-1, -2, -3, -4, -5};
 destination.assign_range(bad); // throws: bad.size() > destination.capacity()
 }
 catch(const std::bad_alloc & ex)
 {
 std::cout << ex.what() << '\n';
 }
}

Possible output:

std::bad_alloc

[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)
Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/container/inplace_vector/assign_range&oldid=175303"

AltStyle によって変換されたページ (->オリジナル) /