Boost logo

Boost :

Subject: [boost] [optional] Suggestion for adding an optional_number class
From: Viktor Sehr (viktor.sehr_at_[hidden])
Date: 2017-07-21 07:47:13


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.

Differences compared to std::optional<int, float, enum etc>:
*- No size overhead from the wrapped type*
- Theoretically faster (althrough in practice probably negilble)
- Can be assigned to any value except the max value
- Operator-> is removed as it does not make sense for an integer

Notes:
- Throws if assigned the numeric_limits<T>::max
- Also works with enums, using the underlying_type
- The operator bool conversion is missing in the prototype implementation

Attaching a prototype implementation (currently for C++14).

/Viktor




Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk