Variadic template bug ?

Funog funog at ifrance.com
Thu Oct 25 13:23:19 PDT 2007


The following code :


import std.stdio;

void Test(literal...)()
{
    foreach(i, foo ; literal)
    {
        static if(foo[0] == '$')
            writefln(foo);
    }
}

void main()
{
    Test!("top", "$tip", "tap")(); //Should output "$tip"
}

won't compile :

jakuz.d(8): Error: expression cast(int)(foo[0u]) == 36 is not constant or does not evaluate to a bool
jakuz.d(8): Error: expression cast(int)(foo[0u]) == 36 is not constant or does not evaluate to a bool
jakuz.d(8): Error: expression cast(int)(foo[0u]) == 36 is not constant or does not evaluate to a bool
jakuz.d(15): template instance jakuz.Test!("top","$tip","$tap") error instantiating


It works by replacing "foo" by "literal[i]" in the static if statement...


import std.stdio;

void Test(literal...)()
{
    int r;
    foreach(i, foo ; literal)
    {
        static if(literal[i][0] == '$')
            writefln(foo);
    }
}

void main()
{
    Test!("top", "$tip", "tap")();
}

Now outputs:
$tip


But shouldn't foo and literal[i] be exactly the same ?







More information about the Digitalmars-d mailing list