How to use labeled break in static foreach?

Adam D. Ruppe destructionator at gmail.com
Fri Feb 14 13:13:18 UTC 2020


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 == whatever)) {
                   passed = false;
             }
         }
         return passed;
     }

     static assert(checkHelper());

     // then foreach to do the rest of it
}


something like that. maybe returning string instead of bool to 
have an error message you print out with the static assert.

i don't love this but it is the simplest way I know.


More information about the Digitalmars-d-learn mailing list