Files
2025-10-25 03:02:53 +03:00

4.1 KiB
Raw Permalink Blame History

[polymorphic.assign]

20 Memory management library [mem]

20.4 Types for composite class design [mem.composite.types]

20.4.2 Class template polymorphic [polymorphic]

20.4.2.5 Assignment [polymorphic.assign]

🔗

constexpr polymorphic& operator=(const polymorphic& other);

1

#

Mandates: T is a complete type.

2

#

Effects: If addressof(other) == this is true, there are no effects.

Otherwise:

  • (2.1)

    The allocator needs updating ifallocator_traits::propagate_on_container_copy_assignment::value is true.

  • (2.2)

    If other is not valueless, a new owned object is constructed in *this usingallocator_traits::construct with the owned object from other as the argument, using either the allocator in *this or the allocator in other if the allocator needs updating.

  • (2.3)

    The previously owned object in *this, if any, is destroyed using allocator_traits::
    destroy and then the storage is deallocated.

  • (2.4)

    If the allocator needs updating, the allocator in *this is replaced with a copy of the allocator in other.

3

#

Returns: A reference to *this.

4

#

Remarks: If any exception is thrown, there are no effects on *this.

🔗

constexpr polymorphic& operator=(polymorphic&& other) noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value || allocator_traits<Allocator>::is_always_equal::value);

5

#

Mandates: If allocator_traits::is_always_equal::value is false,T is a complete type.

6

#

Effects: If addressof(other) == this is true, there are no effects.

Otherwise:

  • (6.1)

    The allocator needs updating ifallocator_traits::propagate_on_container_move_assignment::value is true.

  • (6.2)

    If alloc == other.alloc is true, swaps the owned objects in *this and other; the owned object in other, if any, is then destroyed using allocator_traits::destroy and then the storage is deallocated.

  • (6.3)

    Otherwise, if alloc != other.alloc is true; if other is not valueless, a new owned object is constructed in *this using allocator_traits::construct with the owned object from other as the argument as an rvalue, using either the allocator in *this or the allocator in other if the allocator needs updating.

  • (6.4)

    The previously owned object in *this, if any, is destroyed using allocator_traits::
    destroy and then the storage is deallocated.

  • (6.5)

    If the allocator needs updating, the allocator in *this is replaced with a copy of the allocator in other.

7

#

Returns: A reference to *this.

8

#

Remarks: If any exception is thrown, there are no effects on *this or other.