This will not compile as it says n is not known at compile time:

auto fun(int n) {
        static foreach(i;0..n)
                mixin(i.to!string ~ ".writeln;");
        return; 
}

enum value = 2;


void main() {
        fun(value);
}

But making it a template parameter fun(int n)() and fun!value will obviously work as will replacing n in the foreach statement with the enum 'value'. It seems like a missed opportunity that the enum nature of 'value' does not propagate through the function call letting the compiler know that 'value'and therefore n are known at compile time.

Reply via email to