[Issue 596] Support array, arrayliteral and struct in switch and case
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Aug 15 16:44:30 PDT 2011
http://d.puremagic.com/issues/show_bug.cgi?id=596
--- Comment #7 from bearophile_hugs at eml.cc 2011-08-15 16:44:27 PDT ---
One more useful use is with OOP (this is GUI code):
import core.stdc.stdio;
class Control {}
class Slider : Control {}
class Button : Control {}
void main() {
Control c = new Button;
switch (typeof(c)) {
case Slider: printf("A"); break;
case Button: printf("B"); break;
default: // probably a Control
}
}
That is similar to this (but faster):
import core.stdc.stdio;
class Control {}
class Slider : Control {}
class Button : Control {}
void main() {
Control c = new Button;
if (cast(Slider)c) { printf("A"); }
else if (cast(Button)c) { printf("B"); }
}
--
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