Operator overloading, structs

bearophile bearophileHUGS at lycos.com
Mon Jun 22 01:51:59 PDT 2009


bearophile:
> 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).

It seems I was "right", C# too defines something like it, "true and false operators" (I don't know why they have both of them; isn't one enough?):
http://www.java2s.com/Tutorial/CSharp/0160__Operator-Overload/truefalseoperatorforComplex.htm

There's a certain number of C# features I'd like to see in D (like nullable types that act as nan of floating point numbers, etc).

Bye,
bearophile



More information about the Digitalmars-d mailing list