Subject: Re: [boost] [optional] Suggestion for adding an optional_number class
From: Viktor Sehr (viktor.sehr_at_[hidden])
Date: 2017-07-24 07:29:47
> > I'd like to make a suggestion for adding an optional class for number
> > types, called optional_number, where the max value of the number type is
> > utilized as the uninitalized value.
> What problem are you trying to solve?
The same problem as boost::optional solves for integers\enums\floats, but
without the additional space for a boolean.
In the case of numbers programmers often tend to use magic numbers
(std::string::npos, -1, less than 0, enum::None) etc to indicate
nonexistante index\invalid value etc.
Boost::optional solves this but adds a little overhead in space, using an
optional_number does not.
> - Throws if assigned the numeric_limits<T>::max
> Seems to me the poison is worse than the disease.
I expressed myself badly perhaps, what I mean is that users cannot utilize
the max value in any way. It's hidden inside the optional,
meaning that any handling of the max value is undefined or throws. Perhaps
even a static max member function returning (numeric_limits::max<T>() -1)
should be added.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk