Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would a std::optional<std::nullopt_t> operate?

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?

like image 668
Joshua Green Avatar asked Feb 03 '26 09:02

Joshua Green


1 Answers

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.

like image 114
Nicol Bolas Avatar answered Feb 06 '26 01:02

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!