static if and templates
Oliver
oliver.ruebenkoenig at BLUBweb.de
Fri Sep 28 05:54:48 PDT 2007
Christian and Don,
thanks for you help. Here is what i do now.
1) it is modular
2) is dose not need the clumsy yx!() notation.
thanks again,
oliver
-----------
import std.stdio;
bool isIndexed(T)(T) {
return is( typeof(T[0]) );
}
bool isDoubleIndexed(T)(T) {
return is( typeof(T[0][0]) );
}
bool isSliced(T)(T) {
return is( typeof(T[0..0]) );
}
bool isArray(T)(T expr) {
return isIndexed(expr);
}
bool isMatrix(T)(T expr) {
return isIndexed(expr) && isDoubleIndexed(expr);
}
bool isBlubb(T)(T expr) {
return !isMatrix(expr);
}
void main () {
double s = 1.;
double[] v = [1.,2.];
double[][] m = [[1.,2.]];
writefln("s: ", isArray(s), " ", isMatrix(s) );
writefln("v: ", isArray(v), " ", isMatrix(v) );
writefln("m: ", isArray(m), " ", isMatrix(m) );
writefln("b: ", isBlubb(v), " ", isBlubb(m) );
}
More information about the Digitalmars-d-learn
mailing list