How to use labeled break in static foreach?

visitor pierredavant at gmail.com
Wed Sep 9 17:02:26 UTC 2020


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 THREELOOP = 1; // works with enum, alias etc...
	}
	static if (idx == A.length - 1) {
		static assert(0, "Got no 3...");
	}
     }
}


https://run.dlang.io/is/BDmIml


More information about the Digitalmars-d-learn mailing list