www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Pseudo Members

reply "Vadim Goryunov" <vadim.goryunov gmail.com> writes:
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;

     auto obj = new A();
     obj.empty;   // Error: no property 'empty' for class 'Test.A'
Feb 26 2012
parent reply "Vadim Goryunov" <vadim.goryunov gmail.com> writes:
Apologies, I've just found there is a bug id for this

Feb 26 2012
parent Brad Anderson <eco gnuk.net> writes:
On Sun, Feb 26, 2012 at 3:44 AM, Vadim Goryunov <vadim.goryunov gmail.com>wrote:

 Apologies, I've just found there is a bug id for this


Here's a list of the remaining issues marked as discrepancies between the compiler and the book: http://d.puremagic.com/issues/buglist.cgi?quicksearch=%5Btdpl%5D Referring to that list and also the TDPL errata < http://erdani.com/tdpl/errata/> can be helpful when you encounter something in TDPL that isn't working. Regards, Brad Anderson
Feb 27 2012