A switch/case too far...

Janice Caron caron800 at googlemail.com
Tue May 20 23:26:50 PDT 2008


2008/5/20 Koroskin Denis <2korden at gmail.com>:
> There is a pitfall:
> should the compiler check for logical equality (opEqual) or instance
> equality (is)?

I like the following idea: if the case statement specifies a type,
check that the object can be implicitly cast to that type; if the case
statement specifies a value, check for equality. So:

    switch(typeof(a))
    {
        case B1: // RTTI dynamic cast test
            // ...

        case B2:
            // ...
    }

But

    switch(a)
    {
        case a1: // equality test
            // ...

        case a2:
            // ...
    }



More information about the Digitalmars-d mailing list