Uniform Function Call Syntax?

user001 via Digitalmars-d digitalmars-d at puremagic.com
Thu Mar 3 17:56:34 PST 2016


Was just wondering why UFCS only works in one direction, that is 
why functions can be used as if it were part of a struct/class 
but not the other way around.

struct Vec3
{
     float x;
     float y;
     float z;

     float dot(Vec3 o)
     {
         return x * o.x + y * o.y + z * o.z;
     }
}

int dot;
Vec3 a, b;

float value = dot(a, b); // would be same as a.dot(b)
                          // doesn't try to use local "int dot"


It may not add as much value but I think it'd be a bit better as 
now you no longer have a global function with a simple name 
"dot". For mathematical purposes it is a lot easier to understand 
"dot(a, b)" than "a.dot(b)", at least in my opinion. Just curious 
that's all.


More information about the Digitalmars-d mailing list