digitalmars.D.bugs - [Issue 13247] New: switch doesn't work with pointers to functions.
- via Digitalmars-d-bugs (51/51) Aug 03 2014 https://issues.dlang.org/show_bug.cgi?id=13247
https://issues.dlang.org/show_bug.cgi?id=13247 Issue ID: 13247 Summary: switch doesn't work with pointers to functions. Also casting pointers to functions to integers doesn't work during compilation. Product: D Version: D2 Hardware: x86 OS: Mac OS X Status: NEW Severity: enhancement Priority: P1 Component: DMD Assignee: nobody puremagic.com Reporter: andrei erdani.com Consider: void fun(T)() {} enum A { _1 = &fun!int, _2 = &fun!string, _3 = &fun!double, } void main(string[] args) { A a = A._1; final switch (a) { case A._1: writeln("eh"); break; case A._2: writeln("meh"); break; case A._3: writeln("neh"); break; } } The enum works but the switch doesn't. Trying to force to integrals: void fun(T)() {} enum A { _1 = cast(size_t) &fun!int, _2 = cast(size_t) &fun!string, _3 = cast(size_t) &fun!double, } void main(string[] args) { A a = A._1; final switch (a) { case A._1: writeln("eh"); break; case A._2: writeln("meh"); break; case A._3: writeln("neh"); break; } } Now the enum doesn't compile. Would be great if at least one of these worked. --
Aug 03 2014