strange CFTE issue

Inquie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Mar 14 19:01:14 PDT 2017


If I do something like

enum X = Methods!(C);

foreach(x; X)
{
     mixin(x);
}

I get an error about x not being a compile time variable. (code 
above is simplified, the error has nothing to do with the form 
but of the foreach(x )

but if I wrap it in a function it works

string foo()
{
enum X = Methods!(C);
string y = "";
foreach(x; X)
{
    y ~= x;
}
  return y;
}

mixin(y);

The only diff, of course, is the foreach in the first case mixes 
in on each iteration, while in the second it doesn't... but it 
shouldn't matter. in both cases x is the same.. and it definitely 
is a compile time constant in both. (Methods is just a wrapper on 
__traits(allMembers) but does some manipulation (stole the code 
from somewhere on the forum))




More information about the Digitalmars-d-learn mailing list