Re: How to use labeled break in static foreach?

2020-09-09 Thread visitor via Digitalmars-d-learn
https://run.dlang.io/is/xiqi4P not pretty :)) but ...

Re: How to use labeled break in static foreach?

2020-09-09 Thread visitor via Digitalmars-d-learn
On Wednesday, 9 September 2020 at 17:02:26 UTC, visitor wrote: On Friday, 14 February 2020 at 06:41:02 UTC, cc wrote: import std.meta; enum A = AliasSeq!(1, 2, 3, 4); static foreach (idx, field; A) { static if (__traits(compiles, THREELOOP)) {} else { static if (field == 3) {

Re: How to use labeled break in static foreach?

2020-09-09 Thread visitor via Digitalmars-d-learn
On Friday, 14 February 2020 at 06:41:02 UTC, cc wrote: import std.meta; enum A = AliasSeq!(1, 2, 3, 4); static foreach (idx, field; A) { static if (__traits(compiles, THREELOOP)) {} else { static if (field == 3) { pragma(msg, "Got a 3!"); enum

Re: How to use labeled break in static foreach?

2020-02-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/14/20 1:41 AM, cc wrote: import std.meta; enum A = AliasSeq!(1, 2, 3, 4); THREELOOP: static foreach (idx, field; A) { static if (field == 3) {     pragma(msg, "Got a 3!");     break THREELOOP; } static if (idx == A.length - 1) {     static assert(0, "Got no

Re: How to use labeled break in static foreach?

2020-02-14 Thread Adam D. Ruppe via Digitalmars-d-learn
this kind of thing doesn't work super well due to the nature of compile time. My suggestion is to put the checks and the implementation in separate things. void foo(T...)() { static bool checkHelper() { bool passed; static foreach(t; T) { static if(is(t ==

Re: How to use labeled break in static foreach?

2020-02-13 Thread cc via Digitalmars-d-learn
Here's a more involved example of what I'm trying to accomplish. Is there an easier/cleaner way to do this? (This is still a bit reduced, what I'm actually trying to do is compare whether a given variadic typetuple passed to opDispatch is implicitly convertible to one of the parameter

How to use labeled break in static foreach?

2020-02-13 Thread cc via Digitalmars-d-learn
import std.meta; enum A = AliasSeq!(1, 2, 3, 4); THREELOOP: static foreach (idx, field; A) { static if (field == 3) { pragma(msg, "Got a 3!"); break THREELOOP; } static if (idx == A.length - 1) { static assert(0, "Got no