std::make_optional (3) - Linux Manuals

std::make_optional: std::make_optional

NAME

std::make_optional - std::make_optional

Synopsis


Defined in header <optional>
template< class T > (1) (since C++17)
constexpr std::optional<std::decay_t<T>> make_optional( T&& value );
template< class T, class... Args > (2) (since C++17)
constexpr std::optional<T> make_optional( Args&&... args );
template< class T, class U, class... Args > (3) (since C++17)
constexpr std::optional<T> make_optional( std::initializer_list<U> il, Args&&... args );


1) Creates an optional object from value. Effectively calls std::optional<std::decay_t<T>>(std::forward<T>(value))
2) Creates an optional object constructed in-place from args.... Equivalent to return std::optional<T>(std::in_place, std::forward<Args>(args)...);.
3) Creates an optional object constructed in-place from il and args.... Equivalent to return std::optional<T>(std::in_place, il, std::forward<Args>(args)...);.

Parameters


value - the value to construct optional object with
il, args - arguments to be passed to the constructor of T.

Return value


The constructed optional object.

Exceptions


Throws any exception thrown by the constructor of T.

Notes


T need not be movable for overloads (2-3) due to guaranteed copy elision.

See also


              constructs the optional object
constructor (public member function)