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

5.9 KiB
Raw Permalink Blame History

[indirect.assign]

20 Memory management library [mem]

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

20.4.1 Class template indirect [indirect]

20.4.1.5 Assignment [indirect.assign]

🔗

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

1

#

Mandates:

is_copy_assignable_v is true, and

is_copy_constructible_v is true.

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 valueless,*this becomes valueless and the owned object in *this, if any, is destroyed using allocator_traits::destroy and then the storage is deallocated.

  • (2.3)

    Otherwise, if alloc == other.alloc is true and*this is not valueless, equivalent to **this = *other.

  • (2.4)

    Otherwise a new owned object is constructed in *this using allocator_traits::con
    struct 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.5)

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

  • (2.6)

    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, the result of the expression this->valueless_after_move() remains unchanged.

If an exception is thrown during the call to T's selected copy constructor, no effect.

If an exception is thrown during the call to T's copy assignment, the state of its owned object is as defined by the exception safety guarantee ofT's copy assignment.

🔗

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

5

#

Mandates: is_copy_constructible_t is true.

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 other is valueless,*this becomes valueless and the owned object in *this, if any, is destroyed using allocator_traits::destroy and then the storage is deallocated.

  • (6.3)

    Otherwise, 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.4)

    Otherwise, constructs a new owned object with the owned object of other as the argument as an rvalue, using either the allocator in *this or the allocator in other if the allocator needs updating.

  • (6.5)

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

  • (6.6)

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

7

#

Postconditions: other is valueless.

8

#

Returns: A reference to *this.

9

#

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

🔗

template<class U = T> constexpr indirect& operator=(U&& u);

10

#

Constraints:

is_same_v<remove_cvref_t, indirect> is false,

is_constructible_v<T, U> is true, and

is_assignable_v<T&, U> is true.

11

#

Effects: If *this is valueless then constructs an owned object of type T with std::forward(u) using the allocator alloc.

Otherwise, equivalent to **this = std::forward(u).

12

#

Returns: A reference to *this.