Pseudo Members

Vadim Goryunov vadim.goryunov at gmail.com
Sun Feb 26 02:37:33 PST 2012


In "The D programming language" chapter 5.9.1 Pseudo Members 
Andrei says that D rewrites a.fun(b,c,d) as fun(a,b,c,d) if fun 
is not a member of a's type.
In the following example this is working for arrays only (T[]), 
but not for user defined class A.
Are pseudo members going to be implemented for user defined types 
eventually? Or is it considered a "hack" for arrays only?

class A {
     @property int length() { return 0; }
}

@property bool empty(T)(T a) { return a.length == 0; }

unittest {
     int[] array;
     array.empty;

     auto obj = new A();
     obj.empty;   // Error: no property 'empty' for class 'Test.A'
}




More information about the Digitalmars-d mailing list