Template class with dispatched properties

Ross Hays throwaway at email.net
Thu Nov 7 18:13:00 PST 2013


I have been playing around with a vector implementation that I am
trying to write in D, and have been having problems getting
something to work (it probably isn't even possible).

My end goal is to be able to instantiate a vector with a syntax
like...
`Vector!(2, float) vec = new Vector!(2, float)();`

Now this part I can get working by having `class Vector(int i,
T)` and an array such as `T[i] data`. The thing that I have been
trying to do, is allow access to the components of the vector
through properties that are identified by letter. Ideally it
would work like `vec.x = 4.0f;` or something like that. I have
tried using @property and the opDispatch method together, but
that does not compile. I know I can just use array indicies to
access components, but first I wanted to see if this was possible.

Any suggestions?

Thank you,

Ross Hays


More information about the Digitalmars-d-learn mailing list