Good day to all!

I've been thinking. In D you can write a similar design to the generic functions or somewhere, use static if:

// -----
static if (is(T == short) || is(T == int) || is(T == long)) {
        // do anything
} else static if (is(T == real)) {
        // ...
} else static if (is(T == char)) {
        // ...
} else static if (is(T == string)) {
        // ...
} else static if (is(T == int[])) {
        // ...
} else {
        // ...
}

Why not put in Phobos shorter design type switch:

// -----
type switch (T) {
case short, int, long:
        // do anything
case real:
        // ...
case char:
        // ...
case string:
        // ...
case int[]:
        // ...
default:
        // ...
}

This design has been implemented, for example, in Common Lisp (typecase):
http://www.lispworks.com/documentation/lw51/CLHS/Body/m_tpcase.htm

What do you think about this?

Reply via email to