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);
Effects:
  • If this->has_­value() && rhs.has_­value() is true, no effects.
  • Otherwise, if this->has_­value() is true, equivalent to: construct_­at(addressof(unex), rhs.unex); has_­val = false;
  • Otherwise, if rhs.has_­value() is true, destroys unex and sets has_­val to true.
  • Otherwise, equivalent to unex = rhs.error().
Returns: *this.
Remarks: This operator is defined as deleted unless is_­copy_­assignable_­v<E> is true and is_­copy_­constructible_­v<E> is true.
constexpr expected& operator=(expected&& rhs) noexcept(see below);
Effects:
  • If this->has_­value() && rhs.has_­value() is true, no effects.
  • Otherwise, if this->has_­value() is true, equivalent to: construct_at(addressof(unex), std::move(rhs.unex)); has_val = false;
  • Otherwise, if rhs.has_­value() is true, destroys unex and sets has_­val to true.
  • Otherwise, equivalent to unex = rhs.error().
Returns: *this.
Remarks: The exception specification is equivalent to is_­nothrow_­move_­constructible_­v<E> && is_­nothrow_­move_­assignable_­v<E>.
This operator is defined as deleted unless is_­move_­constructible_­v<E> is true and is_­move_­assignable_­v<E> is true.
template<class G> constexpr expected& operator=(const unexpected<G>& e); template<class G> constexpr expected& operator=(unexpected<G>&& e);
Let GF be const G& for the first overload and G for the second overload.
Constraints: is_­constructible_­v<E, GF> is true and is_­assignable_­v<E&, GF> is true.
Effects:
  • If has_­value() is true, equivalent to: construct_at(addressof(unex), std::forward<GF>(e.value())); has_val = false;
  • Otherwise, equivalent to: unex = std​::​forward<GF>(e.value());
Returns: *this.
constexpr void emplace() noexcept;
Effects: If has_­value() is false, destroys unex and sets has_­val to true.