Re: Compile time foreach with switch

2017-04-24 Thread Nick Treleaven via Digitalmars-d-learn
On Saturday, 22 April 2017 at 11:56:31 UTC, Nick Treleaven wrote: If I compile the above I get: Deprecation: switch case fallthrough - use 'goto default;' if intended IMO the compiler should issue this warning with the OP's code. https://issues.dlang.org/show_bug.cgi?id=7390#c4

Re: Compile time foreach with switch

2017-04-22 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 21 April 2017 at 19:17:32 UTC, Adam D. Ruppe wrote: Then realize that it does exactly the same thing when it is inside a switch... it always breaks the innermost thing, which happens to be this loop. (note that cases are not `breaked`, the switch is.) By coincidence I ran into

Re: Compile time foreach with switch

2017-04-21 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, Apr 21, 2017 at 07:17:32PM +, Adam D. Ruppe via Digitalmars-d-learn wrote: > On Friday, 21 April 2017 at 19:09:25 UTC, Johan Fjeldtvedt wrote: > > void foo(string s) { > > enum es = tuple("a", "b", "c"); > > switch (s) { > > foreach (e; es) { > > case e: > >

Re: Compile time foreach with switch

2017-04-21 Thread Johan Fjeldtvedt via Digitalmars-d-learn
On Friday, 21 April 2017 at 19:17:32 UTC, Adam D. Ruppe wrote: On Friday, 21 April 2017 at 19:09:25 UTC, Johan Fjeldtvedt wrote: void foo(string s) { enum es = tuple("a", "b", "c"); switch (s) { foreach (e; es) { case e: writeln("matched ", e);

Re: Compile time foreach with switch

2017-04-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 21 April 2017 at 19:09:25 UTC, Johan Fjeldtvedt wrote: void foo(string s) { enum es = tuple("a", "b", "c"); switch (s) { foreach (e; es) { case e: writeln("matched ", e); break; } Let me remove some surrounding stuff and ask you

Compile time foreach with switch

2017-04-21 Thread Johan Fjeldtvedt via Digitalmars-d-learn
I was a bit surprised to find out (https://forum.dlang.org/post/csiwyetjkttlxxnwn...@forum.dlang.org) that compile time foreach-loops can be used inside switch-statements. I tried the following: import std.stdio; import std.typecons; void foo(string s) { enum es = tuple("a", "b", "c");