Templated vec
bearophile
bearophileHUGS at lycos.com
Sat Sep 25 07:04:34 PDT 2010
This is an array struct template, this code compiles:
struct Vec(size_t N) {
void opBinary(string op:"~", size_t M)(int[M]) {}
}
void main() {
Vec!2 a1;
int[3] a2;
a1 ~ a2; // OK
}
But this code doesn't compile:
struct Vec(size_t N) {
void opBinary(string op:"~", size_t M)(Vec!M) {}
}
void main() {
Vec!2 a1;
Vec!3 a2;
a1 ~ a2; // line 7, Error
}
DMD 2.049 shows:
test.d(7): Error: cannot implicitly convert expression (a2) of type Vec!(3) to Vec!(M)
Can you show me how to fix the second program?
Bye and thank you,
bearophile
More information about the Digitalmars-d-learn
mailing list