Files
cppdraft_translate/cppdraft/expected/object/obs.md
2025-10-25 03:02:53 +03:00

6.4 KiB
Raw Blame History

[expected.object.obs]

22 General utilities library [utilities]

22.8 Expected objects [expected]

22.8.6 Class template expected [expected.expected]

22.8.6.6 Observers [expected.object.obs]

🔗

constexpr const T* operator->() const noexcept; constexpr T* operator->() noexcept;

1

#

Hardened preconditions: has_value() is true.

2

#

Returns: addressof(val).

🔗

constexpr const T& operator*() const & noexcept; constexpr T& operator*() & noexcept;

3

#

Hardened preconditions: has_value() is true.

4

#

Returns: val.

🔗

constexpr T&& operator*() && noexcept; constexpr const T&& operator*() const && noexcept;

5

#

Hardened preconditions: has_value() is true.

6

#

Returns: std::move(val).

🔗

constexpr explicit operator bool() const noexcept; constexpr bool has_value() const noexcept;

7

#

Returns: has_val.

🔗

constexpr const T& value() const &; constexpr T& value() &;

8

#

Mandates: is_copy_constructible_v is true.

9

#

Returns: val, if has_value() is true.

10

#

Throws: bad_expected_access(as_const(error())) if has_value() is false.

🔗

constexpr T&& value() &&; constexpr const T&& value() const &&;

11

#

Mandates: is_copy_constructible_v is true andis_constructible_v<E, decltype(std::move(error()))> is true.

12

#

Returns: std::move(val), if has_value() is true.

13

#

Throws: bad_expected_access(std::move(error())) if has_value() is false.

🔗

constexpr const E& error() const & noexcept; constexpr E& error() & noexcept;

14

#

Hardened preconditions: has_value() is false.

15

#

Returns: unex.

🔗

constexpr E&& error() && noexcept; constexpr const E&& error() const && noexcept;

16

#

Hardened preconditions: has_value() is false.

17

#

Returns: std::move(unex).

🔗

template<class U = remove_cv_t<T>> constexpr T value_or(U&& v) const &;

18

#

Mandates: is_copy_constructible_v is true andis_convertible_v<U, T> is true.

19

#

Returns: has_value() ? **this : static_cast(std::forward(v)).

🔗

template<class U = remove_cv_t<T>> constexpr T value_or(U&& v) &&;

20

#

Mandates: is_move_constructible_v is true andis_convertible_v<U, T> is true.

21

#

Returns: has_value() ? std::move(**this) : static_cast(std::forward(v)).

🔗

template<class G = E> constexpr E error_or(G&& e) const &;

22

#

Mandates: is_copy_constructible_v is true andis_convertible_v<G, E> is true.

23

#

Returns: std::forward(e) if has_value() is true,error() otherwise.

🔗

template<class G = E> constexpr E error_or(G&& e) &&;

24

#

Mandates: is_move_constructible_v is true andis_convertible_v<G, E> is true.

25

#

Returns: std::forward(e) if has_value() is true,std::move(error()) otherwise.