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

2.8 KiB
Raw Permalink Blame History

[optional.ref.monadic]

22 General utilities library [utilities]

22.5 Optional objects [optional]

22.5.4 Partial specialization of optional for reference types [optional.optional.ref]

22.5.4.7 Monadic operations [optional.ref.monadic]

🔗

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

1

#

Let U be invoke_result_t<F, T&>.

2

#

Mandates: remove_cvref_t is a specialization of optional.

3

#

Effects: Equivalent to:if (has_value()) {return invoke(std::forward(f), *val);} else {return remove_cvref_t();}

🔗

template<class F> constexpr optional<remove_cv_t<invoke_result_t<F, T&>>> transform(F&& f) const;

4

#

Let U be remove_cv_t<invoke_result_t<F, T&>>.

5

#

Mandates: The declarationU u(invoke(std::forward(f), *val)); is well-formed for some invented variable u.

[Note 1:

There is no requirement that U is movable ([dcl.init.general]).

— end note]

6

#

Returns: If *this contains a value, an optional object whose contained value is direct-non-list-initialized withinvoke(std::forward(f), *val); otherwise, optional().

🔗

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

7

#

Constraints: F models invocable.

8

#

Mandates: is_same_v<remove_cvref_t<invoke_result_t>, optional> is true.

9

#

Effects: Equivalent to:if (has_value()) {return *val;} else {return std::forward(f)();}