digitalmars.D - `static switch` statement?
- octo (3/3) Sep 16 2019 `static switch` would make a nice addition to `static if`,
- Max Haughton (4/7) Sep 16 2019 Could it be done as static foreach (blah; blah) {static if (...)
- Andrei Alexandrescu (16/20) Sep 16 2019 It doesn't seem to add power to the language. "static try" would be way
- jmh530 (9/15) Sep 16 2019 Wouldn't it add the comparable amount of power on the
`static switch` would make a nice addition to `static if`, `static foreach`, etc. Any thoughts?
Sep 16 2019
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 2019
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 2019
On Tuesday, 17 September 2019 at 01:05:28 UTC, Andrei Alexandrescu wrote:On 9/16/19 6:41 PM, octo wrote: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.`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]
Sep 16 2019