Subject: Re: [boost] [optional] Safe optional
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2014-11-23 18:14:04
On 21/11/2014 11:42, Olaf van der Spek wrote:
> What do other languages do? Do they have something like optional? How
> are comparisons defined?
In .NET, Nullable<T>:
- has implicit T-to-Nullable<T> conversion & construction
- has explicit Nullable<T>-to-T conversion (which throws an exception
if it has no value)
- can either access "HasValue" and "Value" properties directly or use
a "value_or" style method.
- supports equality testing (two nulls are equal); due to the way that
default language conversions work this applies to both T and Nullable<T>.
- supports "getting a suitable hash value" as an operation, similar to
- does NOT support comparisons other than equality directly, although
there is an explicit comparison method Nullable.Compare<T> that can be
called to do so; it operates only on two Nullable<T>s but implicit
conversion will allow a T to be passed in unadorned.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk