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

8.9 KiB
Raw Permalink Blame History

[expected.void.monadic]

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.7 Monadic operations [expected.void.monadic]

🔗

template<class F> constexpr auto and_then(F&& f) &; template<class F> constexpr auto and_then(F&& f) const &;

1

#

Let U be remove_cvref_t<invoke_result_t>.

2

#

Constraints: is_constructible_v<E, decltype(error())>> is true.

3

#

Mandates: U is a specialization of expected andis_same_v<U::error_type, E> is true.

4

#

Effects: Equivalent to:if (has_value())return invoke(std::forward(f));elsereturn U(unexpect, error());

🔗

template<class F> constexpr auto and_then(F&& f) &&; template<class F> constexpr auto and_then(F&& f) const &&;

5

#

Let U be remove_cvref_t<invoke_result_t>.

6

#

Constraints: is_constructible_v<E, decltype(std::move(error()))> is true.

7

#

Mandates: U is a specialization of expected andis_same_v<U::error_type, E> is true.

8

#

Effects: Equivalent to:if (has_value())return invoke(std::forward(f));elsereturn U(unexpect, std::move(error()));

🔗

template<class F> constexpr auto or_else(F&& f) &; template<class F> constexpr auto or_else(F&& f) const &;

9

#

Let G be remove_cvref_t<invoke_result_t<F, decltype(error())>>.

10

#

Mandates: G is a specialization of expected andis_same_v<G::value_type, T> is true.

11

#

Effects: Equivalent to:if (has_value())return G();elsereturn invoke(std::forward(f), error());

🔗

template<class F> constexpr auto or_else(F&& f) &&; template<class F> constexpr auto or_else(F&& f) const &&;

12

#

Let G beremove_cvref_t<invoke_result_t<F, decltype(std::move(error()))>>.

13

#

Mandates: G is a specialization of expected andis_same_v<G::value_type, T> is true.

14

#

Effects: Equivalent to:if (has_value())return G();elsereturn invoke(std::forward(f), std::move(error()));

🔗

template<class F> constexpr auto transform(F&& f) &; template<class F> constexpr auto transform(F&& f) const &;

15

#

Let U be remove_cv_t<invoke_result_t>.

16

#

Constraints: is_constructible_v<E, decltype(error())> is true.

17

#

Mandates: U is a valid value type for expected.

If is_void_v isfalse, the declarationU u(invoke(std::forward(f))); is well-formed.

18

#

Effects:

  • (18.1)

    If has_value() is false, returnsexpected<U, E>(unexpect, error()).

  • (18.2)

    Otherwise, if is_void_v is false, returns anexpected<U, E> object whose has_val member is true andval member is direct-non-list-initialized withinvoke(std::forward(f)).

  • (18.3)

    Otherwise, evaluates invoke(std::forward(f)) and then returnsexpected<U, E>().

🔗

template<class F> constexpr auto transform(F&& f) &&; template<class F> constexpr auto transform(F&& f) const &&;

19

#

Let U be remove_cv_t<invoke_result_t>.

20

#

Constraints: is_constructible_v<E, decltype(std::move(error()))> is true.

21

#

Mandates: U is a valid value type for expected.

If is_void_v isfalse, the declarationU u(invoke(std::forward(f))); is well-formed.

22

#

Effects:

  • (22.1)

    If has_value() is false, returnsexpected<U, E>(unexpect, std::move(error())).

  • (22.2)

    Otherwise, if is_void_v is false, returns anexpected<U, E> object whose has_val member is true andval member is direct-non-list-initialized withinvoke(std::forward(f)).

  • (22.3)

    Otherwise, evaluates invoke(std::forward(f)) and then returnsexpected<U, E>().

🔗

template<class F> constexpr auto transform_error(F&& f) &; template<class F> constexpr auto transform_error(F&& f) const &;

23

#

Let G be remove_cv_t<invoke_result_t<F, decltype(error())>>.

24

#

Mandates: G is a valid template argument for unexpected ([expected.un.general]) and the declarationG g(invoke(std::forward(f), error())); is well-formed.

25

#

Returns: If has_value() is true, expected<T, G>(); otherwise, anexpected<T, G> object whose has_val member is false and unex member is direct-non-list-initialized withinvoke(std::forward(f), error()).

🔗

template<class F> constexpr auto transform_error(F&& f) &&; template<class F> constexpr auto transform_error(F&& f) const &&;

26

#

Let G beremove_cv_t<invoke_result_t<F, decltype(std::move(error()))>>.

27

#

Mandates: G is a valid template argument for unexpected ([expected.un.general]) and the declarationG g(invoke(std::forward(f), std::move(error()))); is well-formed.

28

#

Returns: If has_value() is true, expected<T, G>(); otherwise, anexpected<T, G> object whose has_val member is false and unex member is direct-non-list-initialized withinvoke(std::forward(f), std::move(error())).