Templated vec
bearophile
bearophileHUGS at lycos.com
Sat Sep 25 08:05:35 PDT 2010
This version works, but it requires a hidden field with distinct name (and no gensym at compile time is available). Do you know a better solution that avoids the need for the distinct hidden field?
struct Vec(size_t N) {
enum size_t _hiddenVecLength = N;
void opBinary(string op:"~", T)(T) if (IsVec!T) {}
}
struct Fake(size_t N) {
enum size_t _hiddenVecLength = N;
}
template IsVec(T) {
enum bool IsVec = is(typeof(T._hiddenVecLength) == size_t)
/* && is(T == Vec!(T._hiddenVecLength)) */ ;
}
void main() {
Vec!2 a1;
Vec!3 a2;
a1 ~ a2;
Fake!3 f;
a1 ~ f; // bug
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list