Metaprogramming with D.

Agustin agustin.l.alvarez at hotmail.com
Sat Oct 19 08:22:30 PDT 2013


I'm trying to implement a template Vector and i would like to 
know if this is possible.

My current vector class is:

public class Vector(T, size_t size) {
     private T components[size];
}

And i would like to implement a property as this:

@property
public size_t length() const {
     return Trait.ExpandFor(size, components, Function(+, (n, 
j))); // Kind of messy but you get my point.
}

instead of doing for(...) over a array i would like to make a 
trait that produce this code

return (x * x + y * y + z * z + ...)



More information about the Digitalmars-d-learn mailing list