http://d.puremagic.com/issues/show_bug.cgi?id=11070
[email protected] changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] --- Comment #1 from [email protected] 2013-09-19 13:16:07 PDT --- (In reply to comment #0) > Additionally, such a variable > shouldn't be visible outside the switch statement if it's only going to be > used > inside of the switch statement. That's easy solved: auto get() { return "c"; } void main() { import std.string; { auto res = get; switch (res) { case "a": break; case "b": break; default: assert(0, format("Unhandled case: '%s'", res)); } } // res not visible here. } > This will also eliminate the need for code duplication in switch statements > which use a common label statement, for example: > > ----- > import std.string; > import std.stdio; > > auto get() { return "d"; } > > void main() > { > switch (auto res = get()) > { > case "a": goto common; > case "b": goto common; > case "c": goto common; > > common: > writefln("Got result: %s", res); > break; > > default: assert(0, format("Unhandled case: '%s'", res)); > } > } Usually common bodies for case statements are not a big problem in D: auto get() { return "d"; } void main() { import std.stdio, std.string; { auto res = get; switch (res) { case "a", "b", "c": writefln("Got result: %s", res); break; default: assert(0, format("Unhandled case: '%s'", res)); } } // res not visible here. } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
