The boost::optional C++ library has 'no value' indicated by boost::none, which is a well-chosen name as code like
f(..., optional<T> default_argument = boost::none)
or
f(..., optional<T> default_argument = none)
is very readable -- the intent is clearly communicated to the reader. It's also similar to the 'no value' provided in standard classes in other languages. This Boost library was absorbed into the standard as std::experimental::optional, but none was renamed to the inscrutable nullopt_t. Does anyone know why?
Funnily, it turned out to be easier to standardize boost::optional than to standardize boost::none. boost::none, while it serves its purpose of initializing boost::optionals, it doesn't have well-defined semantics.
A good well-behaved value-semantic alternative to void is useful, but requires a lot of questions to be answered. Should it have operator< and be an Ordered type? Should it be inter-convertibe with nullptr? Comparable with nullptr? I did not want these questions to impede the adoption of boost::optional, so we agreed on a compromise. For now, go with nullopt whose only purpose is to initialize optional objects. Add a well-behaved none later. And indeed a work on 'prefect' none is in progress. See here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With