I don\'t understand the reasoning for the inclusion of std::nullopt_t
in the standard. Does it exist strictly for convenience, or is it required in some niche c
C++ reference says it all:
std::nullopt_t
is an empty class type used to indicateoptional
type with uninitialized state. In particular,std::optional
has a constructor withnullopt_t
as a single argument, which creates anoptional
that does not contain a value.
std::nullopt_t
nullopt_t
is the type of nullopt
which indicates disengaged optional
state. nullopt
allows disambiguating overloads such as (example from the optional
proposal):
void run(complex<double> v); void run(optional<string> v); run(nullopt); // pick the second overload run({}); // ambiguous