Namespaces
Variants

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

From cppreference.net

template < container-compatible-range < T > R >
constexpr void assign_range ( R && rg ) ;
(C++26부터)

컨테이너의 요소들을 rg 의 각 요소 사본으로 대체합니다.

범위 내의 각 반복자는 rg 정확히 한 번 역참조됩니다.

만약 rg * this 와 겹치는 경우, 동작은 정의되지 않습니다.

목차

매개변수

rg - 컨테이너의 요소 타입으로 변환 가능한 참조 타입을 가진 input_range
타입 요구사항
-
만약 std:: assignable_from < T & , ranges:: range_reference_t < R >> 가 모델되지 않으면, 프로그램의 형식이 잘못되었습니다.
-
만약 T * ranges:: begin ( rg ) 에서 inplace_vector EmplaceConstructible 가 아니면, 동작은 정의되지 않습니다.

예외

예제

#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';
    }
}

가능한 출력:

std::bad_alloc

참고 항목

요소 범위를 삽입합니다
(public member function)
끝에 요소 범위를 추가합니다
(public member function)
컨테이너에 값을 할당합니다
(public member function)
컨테이너에 값을 할당합니다
(public member function)