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 circumstances?
To be clear, I understand that it is used as an argument to construct empty std::optional
objects. But considering a default constructor for std::optional
already exists, there seems to be no obvious motivation for the existence of std::nullopt_t
. Must such a constructor and assignment operator exist for std::optional
to conform to a particular concept? If so, which concept?
Best Answer
nullopt_t
is the type ofnullopt
which indicates disengagedoptional
state.nullopt
allows disambiguating overloads such as (example from theoptional
proposal):