foreach on a tuple in CTF

Max Samukha samukha at voliacable.com
Tue Apr 24 12:31:20 PDT 2007


Why the function cannot be evaluated at compile time? Is it a bug? 

import std.stdio;

char[] foo(A...)()
{
    char[] s = "";

    foreach (i, v; A)
    {
        static if (i == 1)
            s = i.stringof;
    }

    return s;
}

void main(char[][] args)
{
    alias foo!("test", 100) f;

    writefln(f());		// works				
    pragma(msg, f());	// error: cannot evaluate at compile time
}


More information about the Digitalmars-d-learn mailing list