Operator overloading, structs
bearophile
bearophileHUGS at lycos.com
Wed Jun 10 05:27:58 PDT 2009
Don:
> The only time when you want to allow an implicit conversion to bool is
> when you have some kind of "smart bool" struct which is supposed to be a
> drop-in replacement for "bool". It's quite distinct from
> if(x) --> if(x!=0).
When the complex numbers are implemented by a struct in the standard library (or as in the original case of BigInts), I may like to keep being able to write:
if (x) { ... }
Where x is a Complex struct or BigInt struct that defines something like an opBool.
In both those situations you can write:
if (x != 0) { ... }
They just need to define opEquals(int).
Bye,
bearophile
More information about the Digitalmars-d
mailing list