Namespaces
Variants

std::polymorphic<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 polymorphic & operator = ( const polymorphic & other ) ;
(1) (C++26부터)
constexpr polymorphic & operator = ( polymorphic && other )
noexcept ( /* 아래 참조 */ ) ;
(2) (C++26부터)

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

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

1) 만약 std:: addressof ( other ) == this true 이면, 아무 작업도 수행하지 않습니다. 그렇지 않으면, need_update traits :: propagate_on_container_copy_assignment :: value 로 설정합니다:
  1. 만약 other 가 값을 가지지 않으면 다음 단계로 진행합니다. 그렇지 않으면, * other 를 인자로 사용하여 traits :: construct 와 할당자 update_alloc ? other. alloc : alloc 를 사용하여 * this 에 새로운 소유 객체를 생성합니다.
  2. * this 에 이전에 소유했던 객체(있는 경우)는 traits :: destroy 를 사용하여 파괴된 후 저장 공간이 할당 해제됩니다.
* this 가 소유한 객체를 업데이트한 후, need_update true 인 경우, alloc other. alloc 의 복사본으로 대체됩니다.
만약 T incomplete type 인 경우, 프로그램은 ill-formed입니다.
2) 만약 std:: addressof ( other ) == this true 이면, 아무 작업도 수행하지 않습니다. 그렇지 않으면, need_update traits :: propagate_on_container_move_assignment :: value 로 설정합니다:
  • 만약 alloc == other. alloc true 이면, * this other 의 소유 객체를 교환합니다; other 의 소유 객체(존재하는 경우)는 traits :: destroy 를 사용하여 파괴된 후 저장 공간이 해제됩니다.
  • 그렇지 않으면:
  1. 만약 other 가 값이 없는 상태(valueless)이면 다음 단계로 진행합니다. 그렇지 않으면, * this 에 새로운 소유 객체를 traits :: construct 를 사용하여 std :: move ( * other ) 를 인자로 하여 구성하며, 할당자 update_alloc ? other. alloc : alloc 를 사용합니다.
  2. * this 의 이전 소유 객체(존재하는 경우)는 traits :: destroy 를 사용하여 파괴된 후 저장 공간이 해제됩니다.
* this other 가 소유한 객체들을 업데이트한 후, need_update true 인 경우, alloc other. alloc 의 복사본으로 대체됩니다.
다음 조건들이 모두 충족되면 프로그램은 형식에 맞지 않습니다(ill-formed):
  • std:: allocator_traits < Allocator > :: is_always_equal :: value false 인 경우.
  • T 가 불완전한 타입(incomplete type)인 경우.

목차

매개변수

other - 할당에 사용되는 소유된 값(존재하는 경우)을 가진 또 다른 polymorphic 객체

반환값

* this

예외

1) 예외가 발생하면, * this 에는 아무런 영향이 없습니다.
2) 예외가 발생하면, * this 또는 other 에 아무런 영향도 미치지 않습니다.
noexcept 명세:
noexcept ( std:: allocator_traits < Allocator > ::

propagate_on_container_move_assignment :: value

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

예제