Namespaces
Variants

std::indirect<T, Allocator>:: operator=

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
constexpr indirect & operator = ( const indirect & other ) ;
(1) (C++26부터)
constexpr indirect & operator = ( indirect && other ) noexcept ( /* 아래 참조 */ ) ;
(2) (C++26부터)
template < class U = T >
constexpr indirect & operator = ( U && value ) ;
(3) (C++26부터)

* this 의 내용을 value 또는 other 의 내용으로 대체합니다.

traits std:: allocator_traits < Allocator > 로 정의합니다:

1) 만약 std:: addressof ( other ) == this true 이면, 아무 작업도 수행하지 않습니다. 그렇지 않으면, need_update traits :: propagate_on_container_copy_assignment :: value 로 설정합니다:
  • 만약 other 가 값을 가지지 않으면, * this 는 값을 가지지 않게 되고, * this 가 소유한 객체(있는 경우)는 traits :: destroy 를 사용하여 파괴된 후 저장 공간이 할당 해제됩니다.
  • 그렇지 않고 만약 alloc == other. alloc true 이고 * this 가 값을 가지지 않지 않으면, ** this = * other 와 동등합니다.
  • 그렇지 않으면:
  1. * this 에 새로운 소유 객체를 traits :: construct 를 사용하여 * other 를 인자로 하여 생성하며, 할당자 update_alloc ? other. alloc : alloc 를 사용합니다.
  2. * this 의 이전 소유 객체(있는 경우)는 traits :: destroy 를 사용하여 파괴된 후 저장 공간이 할당 해제됩니다.
  3. p 가 새로운 소유 객체를 가리킵니다.
alloc 가 소유한 객체를 업데이트한 후, need_update true 인 경우, alloc other. alloc 의 복사본으로 대체됩니다.
만약 std:: is_copy_assignable_v < T > && std:: is_copy_constructible_v < T > false 인 경우, 프로그램의 형식이 잘못되었습니다.
2) 만약 std:: addressof ( other ) == this true 이면, 아무 작업도 수행하지 않습니다. 그렇지 않으면, need_update traits :: propagate_on_container_move_assignment :: value 로 설정합니다:
  • 만약 other 가 값을 가지지 않으면, * this 는 값을 가지지 않게 되고, * this 가 소유한 객체(있는 경우)는 traits :: destroy 를 사용하여 파괴된 후 저장 공간이 할당 해제됩니다.
  • 그렇지 않고 만약 alloc == other. alloc true 이면, * this other 의 소유 객체를 교환합니다; other 의 소유 객체(있는 경우)는 traits :: destroy 를 사용하여 파괴된 후 저장 공간이 할당 해제됩니다.
  • 그렇지 않으면:
  1. * this 에 새로운 소유 객체를 traits :: construct 를 사용하여 std :: move ( * other ) 를 인자로 하여 생성하며, 할당자로 update_alloc ? other. alloc : alloc 를 사용합니다.
  2. * this 의 이전 소유 객체(있는 경우)는 traits :: destroy 를 사용하여 파괴된 후 저장 공간이 할당 해제됩니다.
  3. p 가 새로운 소유 객체를 가리킵니다.
소유한 객체들을 업데이트한 후에, * this other 가, need_update true 인 경우, alloc other. alloc 의 복사본으로 대체됩니다.
만약 std:: is_copy_constructible_v < T > false 라면, 프로그램의 형식이 올바르지 않습니다.
3) 만약 * this 가 값을 가지지 않으면, alloc 을 사용하여 std:: forward < U > ( value ) 로 소유 객체를 생성합니다. 그렇지 않으면 ** this = std:: forward < U > ( value ) 와 동등합니다.
이 오버로드는 다음의 모든 조건이 만족될 때만 오버로드 해결에 참여합니다:

목차

매개변수

other - 소유된 값(존재하는 경우)이 할당에 사용되는 또 다른 indirect 객체
value - 소유된 값에 할당하거나 생성할 값

반환값

* this

예외

1) 예외가 발생하는 경우, this - > valueless_after_move ( ) 의 결과는 변경되지 않습니다.
T 의 선택된 복사 생성자 호출 중 예외가 발생하면, 아무런 영향도 없습니다.
만약 예외가 T 의 복사 할당 연산자 호출 중에 발생하면, this - > p 의 상태는 T 의 복사 할당 연산자의 예외 안전성 보장에 따라 정의됩니다.
2) 예외가 발생할 경우, * this 또는 other 에 아무런 영향도 미치지 않습니다.
noexcept 명세:
noexcept ( std:: allocator_traits < Allocator > ::

propagate_on_container_move_assignment :: value

|| std:: allocator_traits < Allocator > :: is_always_equal :: value )

예제