Pattern matching in D

bearophile bearophileHUGS at lycos.com
Sun Mar 7 16:43:51 PST 2010


retard:
> So what types does the regular switch accept in D 2 ?

It accepts all integral values, including all chars and true enums. It accepts strings but not arrays.

It doesn't accept floating point values, complex numbers (that are FP), structs, objects and associative arrays.

Eventually support for arrays and structs too can be added, someone in the D Wish list has asked for those two things, but so far I haven't found a need for this.

If D adds tagged structs, then switch can read their tag. Time ago I have thought about an opSwitch operator for structs/classes, that gets called by switch, but I haven had not enough need for something like this so far. So I have never asked for it.

Bye,
bearophile



More information about the Digitalmars-d mailing list