[Issue 596] Support array, arrayliteral and struct in switch and case

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Sep 28 19:14:06 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=596



--- Comment #8 from bearophile_hugs at eml.cc 2011-09-28 19:13:23 PDT ---
Supporting something like this will be very useful (this is done very commonly
in functional languages):


import std.variant: Algebraic;
alias Algebraic!(int, float) A;
void main() {
    A a = 1.5;
    final switch (a.type()) {
        case typeid(int): ...
        case typeid(float): ...        
    }
}

But if possible I suggest to introduce a compiler optimization specific for
this usage, to avoid actually allocating and using TypeInfo class instances.

The advantage of using a final switch instead of a sequence of if statements:
- The code is more readable, the various cases are shown in a more ordered way;
- The "final" of switch makes sure all types of the Algebraic are taken into
account;
- The compiler has ways to optimize this code better (sometimes avoiding many
runtime tests).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list