November 09, 2011 [Issue 6921] New: Request for a 'static final switch' statement | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=6921 Summary: Request for a 'static final switch' statement Product: D Version: unspecified Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: ThatsGobbles@gmail.com --- Comment #0 from Mark LeMoine <ThatsGobbles@gmail.com> 2011-11-09 11:28:40 PST --- I've often come across cases where I find it'd be handy to have a different constructor based on a passed-in template enum parameter: enum Options { Some, Many, All } class OptionManager(Options O) { static if(O == Options.Some) { alias TypeTuple!(int) TP; } else static if(O == Options.Some) { alias TypeTuple!(int, int, int) TP; } else static if(O == Options.Some) { alias TypeTuple!(int, int, int, int, int, int) TP; } else { static assert(0); } public this(TP params) { // ... } } However, this necessitates a static if-else chain, as shown. It would be quite handy to have a static final switch variant for cases like the above. Would this be something easy to implement in the D language? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
May 27, 2012 [Issue 6921] Request for a 'static final switch' statement | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mark LeMoine | http://d.puremagic.com/issues/show_bug.cgi?id=6921 bearophile_hugs@eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |bearophile_hugs@eml.cc --- Comment #1 from bearophile_hugs@eml.cc 2012-05-27 05:54:55 PDT --- Do you mean something like this? It's handy: enum Options { Some, Many, All } class OptionManager(Options opt) { static final switch(opt) { case Options.Some: alias TypeTuple!(int) TP; break; case Options.Many: alias TypeTuple!(int, int, int) TP; break; case Options.All: alias TypeTuple!(int, int, int, int, int, int) TP; break; } public this(TP params) { // ... } } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation