monarch_dodra:

Select!(cond, 1, 2);// This doesn't compile

Time ago I asked for an improvement of Select:
https://github.com/D-Programming-Language/phobos/pull/1235

Maybe there is a way to allow that too:


template Select(bool condition, T...) if (T.length == 2) {
    static if (condition)
        enum Select = T[0];
    else
        enum Select = T[1];
}

void main() {
    enum x = Select!(true, 10, 20);// error
    static assert(x == 10);
    int a = 1;
    int b = 2;
    alias y = Select!(true, a, b);
    assert(y == 1);
    alias T = Select!(true, int, long);
    static assert(is(T == int));
}


How do you tell apart values from not values? :-)

Bye,
bearophile

Reply via email to