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;
Let U be invoke_result_t<F, T&>.
Mandates: remove_cvref_t<U> is a specialization of optional.
Effects: Equivalent to: if (has_value()) { return invoke(std::forward<F>(f), *val); } else { return remove_cvref_t<U>(); }
template<class F> constexpr optional<remove_cv_t<invoke_result_t<F, T&>>> transform(F&& f) const;
Let U be remove_cv_t<invoke_result_t<F, T&>>.
Mandates: The declaration U u(invoke(std::forward<F>(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]
Returns: If *this contains a value, an optional<U> object whose contained value is direct-non-list-initialized with invoke(std​::​forward<F>(f), *val); otherwise, optional<U>().
template<class F> constexpr optional or_else(F&& f) const;
Constraints: F models invocable.
Mandates: is_same_v<remove_cvref_t<invoke_result_t<F>>, optional> is true.
Effects: Equivalent to: if (has_value()) { return *val; } else { return std::forward<F>(f)(); }