Namespaces
Variants

std::inplace_vector<T,N>::operator=

cppreference.net에서
 
 
 
 
constexpr inplace_vector& operator=( const inplace_vector& other );
(1) (C++26부터)
constexpr inplace_vector& operator=( inplace_vector&& other )
    noexcept(/* see below */);
(2) (C++26부터)
constexpr inplace_vector& operator=( std::initializer_list<T> init );
(3) (C++26부터)

inplace_vector의 내용을 대체합니다.

1) 복사 할당 연산자. other의 내용을 복사하여 내용을 대체합니다.
이 연산자는 trivial입니다. 만약 std::inplace_vector<T, N>이 trivially destructible이고 std::is_trivially_copy_constructible_v<T> && std::is_trivially_copy_assignable_v<T>가 true인 경우에만 해당합니다.
2) 이동 할당 연산자. 이동 의미론을 사용하여 other의 내용으로 대체합니다 (즉, other의 데이터가 other에서 이 컨테이너로 이동됩니다). 이후 other은 유효하지만 지정되지 않은 상태에 있습니다.
이 연산자는 trivial입니다. 만약 std::inplace_vector<T, N>이 trivially destructible이고 std::is_trivially_move_constructible_v<T> && std::is_trivially_move_assignable_v<T>가 true인 경우에만 해당합니다.
3) 초기화 리스트 init로 식별된 내용으로 대체합니다.

매개변수

other - 요소를 초기화하는 데 사용할 소스 역할을 하는 또 다른 inplace_vector
init - 컨테이너의 요소를 초기화하는 데 사용할 초기화자 목록

복잡도

1,2) * this 와 other 의 크기에 선형적으로 비례합니다.
3) * this 와 init 의 크기에 선형적입니다.

예외

3) 다음의 경우 std::bad_alloc 을 발생시킵니다: init. size ( ) > N .

예제

#include <initializer_list>
#include <inplace_vector>
#include <new>
#include <print>
#include <ranges>
#include <string>
int main()
{
    std::inplace_vector<int, 4> x({1, 2, 3}), y;
    std::println("초기 상태:");
    std::println("x = {}", x);
    std::println("y = {}", y);
    std::println("복사 할당이 x에서 y로 데이터를 복사합니다:");
    y = x; // 오버로드 (1)
    std::println("x = {}", x);
    std::println("y = {}", y);
    std::inplace_vector<std::string, 3> z, w{"\N{CAT}", "\N{GREEN HEART}"};
    std::println("초기 상태:");
    std::println("z = {}", z);
    std::println("w = {}", w);
    std::println("이동 할당이 w에서 z로 데이터를 이동합니다:");
    z = std::move(w); // 오버로드 (2)
    std::println("z = {}", z);
    std::println("w = {}", w); // w는 유효하지만 지정되지 않은 상태입니다
    auto l = {4, 5, 6, 7};
    std::println("initializer_list {}를 x에 할당:", l);
    x = l; // 오버로드 (3)
    std::println("x = {}", x);
    std::println("N보다 큰 크기의 initializer_list 할당은 예외를 발생시킵니다:");
    try
    {
        x = {1, 2, 3, 4, 5}; // 예외 발생: (initializer list 크기 == 5) > (용량 N == 4)
    }
    catch(const std::bad_alloc& ex)
    {
        std::println("ex.what(): {}", ex.what());
    }
}

가능한 출력:

초기 상태:
x = [1, 2, 3]
y = []
복사 할당이 x에서 y로 데이터를 복사합니다:
x = [1, 2, 3]
y = [1, 2, 3]
초기 상태:
z = []
w = ["🐈", "💚"]
이동 할당이 w에서 z로 데이터를 이동합니다:
z = ["🐈", "💚"]
w = ["", ""]
initializer_list [4, 5, 6, 7]를 x에 할당:
x = [4, 5, 6, 7]
N보다 큰 크기의 initializer_list 할당은 예외를 발생시킵니다:
ex.what(): std::bad_alloc

참고 항목

inplace_vector 를 생성한다
(public member function)
컨테이너에 값을 할당한다
(public member function)