Template class with dispatched properties
Ross Hays
throwaway at email.net
Thu Nov 7 19:42:11 PST 2013
I am actually a little curious why my original approach did not
work at all. Using some of what you provided and some of what I
had I get the following:
import std.stdio;
import std.string;
class Vector(int N, T) if (N <= 3) {
T[N] data;
this()
{
data[] = 0;
}
@property ref T opDispatch(string fieldName, Args ...)(Args
args)
if (Args.length < 2 && fieldName.length == 1 &&
toOffset(fieldName) < N)
{
int offset = fieldName.charAt(0) - 'x';
return data[offset] = args[0];
}
}
void main()
{
Vector!(2, float) t = new Vector!(2,float)();
writeln(t.x);
}
Which still errors out with: Error: no property 'x' for type
'test.Vector!(2, float).Vector'
So that is odd.
More information about the Digitalmars-d-learn
mailing list