Project Elvis
Ola Fosheim Grøstad
ola.fosheim.grostad+dlang at gmail.com
Sun Oct 29 16:29:27 UTC 2017
On Sunday, 29 October 2017 at 15:57:19 UTC, Steven Schveighoffer
wrote:
> I would have expected Nullable!int to fit the bill, but
> unfortunately, opCast(bool) doesn't work on a null Nullable.
>
> But certainly you can construct a type that does work.
The right thing to do is to create a type that you cannot cast to
bool, but where you can test for invalid values and substitute in
a default.
Forcing people to have a boolean interpretation of a type mean
valid/invalid state has viral consequences. It means that if the
type has a zero value then a boolean interpretation of zero now
should give true. That's not good for generic code.
Float and NaN is another use case.
More information about the Digitalmars-d
mailing list