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 std::hash. - 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.