On Wednesday, 4 November 2015 at 00:17:25 UTC, Timon Gehr wrote:
This is identical to the existing Seq-foreach:

auto foo(Args...)(){
    foreach(a;Args){
        pragma(msg,a.stringof);
    }
}

void main(){
    foo!(1,"2",main,int)();
}


It comes very close... but this breaks down(see below). If it had been a real alias, it would have worked, but then again it can't always be lowered to an alias in the general case, since alias has it's own quirks.

Hmm, I guess the real solution is to fix the quirks of alias in a separate DIP, first after that foreach could be changed take advantage of it?

auto foo(Args...)(){
    foreach(a;Args){
        pragma(msg, a.stringof);
    }
}
auto bar(Args...)(){
    foreach(const i, _;Args){
        alias arg = Args[i];
        pragma(msg, arg.stringof);
    }
}

void main(){
  int a,b,c;
  foo!(a,b,c)();
  bar!(a,b,c)();
  foo!(1)();
  // bar!(1)();
}

Reply via email to