Delegator

Adam D. Ruppe destructionator at gmail.com
Sat Mar 3 10:45:30 PST 2012


On Saturday, 3 March 2012 at 16:50:45 UTC, bioinfornatics wrote:
> can w do same in D ?

alias this does that, although it does for all unknown
methods, not specific ones:

struct A {
    int[] data;
    alias data this;
}

A a;

a[0] = 10; // this works like a.data[0] = 10;


alias this also lets you pass the struct
when the member is expected:

void somethingWithArray(int[] arr) {}

A a;
somethingWithArray(a); // works, passes a.data automatically


More information about the Digitalmars-d-learn mailing list