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) {
                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

oops the online editor saved a mix of an old iteration and a new one ... (probably my fault)

import std.stdio;

float test(float x)
{
    float r = -1;
        static foreach(i; 0 .. 100)
        {
            static if (__traits(compiles, Check)) {} else {
                static if (i == 10)
                    enum Check = 1;
                r = i * x;
            }
        }

    return r;
}

void main() {
        float ret = test(4.2);
    writefln("ret = %s", ret);
}

Reply via email to