Kind of a silly question, but I'm curious and I haven't found this explained. Is it legal to construct a std::optional<std::nullopt_t>
? If you did, what would
std::optional<std::nullopt_t> x(std::nullopt);
do? Would x
contain a value or not?
As pointed out in the comments, instantiating a optional
with nullopt_t
(or in_place_t
) is explicitly forbidden and will fail with a compile error.