Map the contained value through func, or return an empty optional.

Synopsis

Declared in <bslstl_optional.h>

template<class t_FUNC>
constexpr
auto
transform(t_FUNC&& func) &;

Description

If this object contains a value, invoke the specified func with the contained value as an argument and return optional<U> that contains the result of that invocation, where U is the cv‐unqualified func return type, which can be different from t_TYPE; otherwise, return an empty optional<U>. Note that func must return an object type other than array, bsl::in_place_t or bsl::nullopt. Also note that there is no requirement that U is movable. Finally note that the returned optional uses the allocator of the object returned by func, or the default allocator if func is not invoked.

Return Value

optional containing the result of func, or empty if disengaged

Parameters

Name

Description

func

callable invoked with the contained value or when empty

Created with MrDocs