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

4.1 KiB
Raw Permalink Blame History

[expected.void.assign]

22 General utilities library [utilities]

22.8 Expected objects [expected]

22.8.7 Partial specialization of expected for void types [expected.void]

22.8.7.4 Assignment [expected.void.assign]

🔗

constexpr expected& operator=(const expected& rhs);

1

#

Effects:

  • (1.1)

    If this->has_value() && rhs.has_value() is true, no effects.

  • (1.2)

    Otherwise, if this->has_value() is true, equivalent to: construct_at(addressof(unex), rhs.unex); has_val = false;

  • (1.3)

    Otherwise, if rhs.has_value() is true, destroys unex and sets has_val to true.

  • (1.4)

    Otherwise, equivalent to unex = rhs.error().

2

#

Returns: *this.

3

#

Remarks: This operator is defined as deleted unlessis_copy_assignable_v is true andis_copy_constructible_v is true.

🔗

constexpr expected& operator=(expected&& rhs) noexcept(see below);

4

#

Constraints: is_move_constructible_v is true andis_move_assignable_v is true.

5

#

Effects:

  • (5.1)

    If this->has_value() && rhs.has_value() is true, no effects.

  • (5.2)

    Otherwise, if this->has_value() is true, equivalent to:construct_at(addressof(unex), std::move(rhs.unex));has_val = false;

  • (5.3)

    Otherwise, if rhs.has_value() is true, destroys unex and sets has_val to true.

  • (5.4)

    Otherwise, equivalent to unex = std::move(rhs.error()).

6

#

Returns: *this.

7

#

Remarks: The exception specification is equivalent tois_nothrow_move_constructible_v && is_nothrow_move_assignable_v.

🔗

template<class G> constexpr expected& operator=(const unexpected<G>& e); template<class G> constexpr expected& operator=(unexpected<G>&& e);

8

#

Let GF be const G& for the first overload andG for the second overload.

9

#

Constraints: is_constructible_v<E, GF> is true andis_assignable_v<E&, GF> is true.

10

#

Effects:

If has_value() is true, equivalent to:construct_at(addressof(unex), std::forward(e.error()));has_val = false;

Otherwise, equivalent to:unex = std::forward(e.error());

11

#

Returns: *this.

🔗

constexpr void emplace() noexcept;

12

#

Effects: If has_value() is false, destroys unex and sets has_val to true.