PROPOSAL: Operator overloading by static member function

BCS ao at pathlink.com
Sun Oct 14 06:36:35 PDT 2007


Reply to Daniel,


> struct Meters
> {
> real value;
> }
> struct m
> {
> static Meters opMul_r(real value)
> {
> return Meters(value);
> }
> }
> auto distance = 20*m;
> 
> In your system, there's no way to have that since you can't have type
> arguments.  And *yes*, there are people who use this kind of thing.
> 
> 

struct SIUnit(int d, int t, int m, int c=0, int k=0, int l=0)
{
 static Meters opMul_r(real value)
 {
 }
}

const m = SIUnit!(1,0,0)(1.0);





More information about the Digitalmars-d mailing list