www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - `static switch` statement?

reply octo <email example.org> writes:
`static switch` would make a nice addition to `static if`, 
`static foreach`, etc.

Any thoughts?
Sep 16
next sibling parent Max Haughton <maxhaton gmail.com> writes:
On Tuesday, 17 September 2019 at 00:41:03 UTC, octo wrote:
 `static switch` would make a nice addition to `static if`, 
 `static foreach`, etc.

 Any thoughts?
Could it be done as static foreach (blah; blah) {static if (...) {} }? I don't know whether the amount of use it would get would be useful relative to the cost of implementing it
Sep 16
prev sibling parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 9/16/19 6:41 PM, octo wrote:
 `static switch` would make a nice addition to `static if`, `static 
 foreach`, etc.
 
 Any thoughts?
It doesn't seem to add power to the language. "static try" would be way better because a typical idiom is: static if (__traits(compiles, { codecodecode })) { codecodecode } It would be way nicer if we had something like: static try { codecodecode } catch (Exception e) { // e.msg contains the compile-time error }
Sep 16
parent jmh530 <john.michael.hall gmail.com> writes:
On Tuesday, 17 September 2019 at 01:05:28 UTC, Andrei 
Alexandrescu wrote:
 On 9/16/19 6:41 PM, octo wrote:
 `static switch` would make a nice addition to `static if`, 
 `static foreach`, etc.
 
 Any thoughts?
It doesn't seem to add power to the language. [snip]
Wouldn't it add the comparable amount of power on the compile-side that the run-time switch statement adds? Run-time switch can be reconstructed as a series of if statements, same thing as compile-time switch. I am not sure I would use the feature, but it reminds me of some attributes being preprended with and others not. It's just one of those quirks of the language.
Sep 16