Variadic templates with aliases
comco
void.unsigned at gmail.com
Thu Dec 27 12:01:54 PST 2012
I wrote a simple template mixin to hold common operator overloads:
mixin template VectorSpaceOpsMixin(Vector, Scalar, alias a, alias
b)
{
Vector opUnary(string op)() if (op == "-") {
return Vector(-a, -b);
}
...
}
This works like this:
struct complex {
double a, b;
mixin VectorSpaceOpsMixin!(complex, double, a, b);
...
}
Now this is nice, but it only works when the vector has 2 parts.
Can the mixin template be made more general? What will then be
its definition? This don't work:
mixin template `VectorSpaceOpsMixin(Vector, Scalar, alias...
parts) { ... }`
Obviously, this kind of functionality is easy with string mixins.
Can it be achieved without them?
More information about the Digitalmars-d-learn
mailing list