Return this optional if engaged; otherwise invoke func.

Synopsis

Declared in <bslstl_optional.h>

template<class t_FUNC>
constexpr
optional<t_TYPE>
or_else(t_FUNC&& func) &&
requires conjunction_v<std::is_invocable<t_FUNC>,
                              std::is_move_constructible<t_TYPE>>;

Description

If this object does not contain a value, invoke the specified func and return the result of that invocation; otherwise, return a move‐constructed value from this object, leaving this object in an unspecified but valid state. Note that func must return bsl::optional. Also note that the optional object returned by func is returned as‐is, without copying or moving.

Return Value

this optional if engaged, otherwise the result of func

Parameters

Name

Description

func

callable invoked with the contained value or when empty

Created with MrDocs