Static foreach.

Nick a at bb.com
Fri Nov 3 02:54:16 PST 2006


Here's a useful example (I think):

void rotLeft(X...)()
{
  typeof(X[0]) tmp = X[0];
  foreach(int i, x; X[1..$])
    X[i] = x;
  X[$-1] = tmp;
}

void main()
{
  int a=1, b=2, c=3;
  rotLeft!(a,b,c); // Should produce a,b,c = 2,3,1
}

Compiling gives the error "Integer constant expression expected instead of i".

I'm using this right now, but instead of being generic, the version I have
contains lots statements like
...
static if(X.length > 2) X[1] = X[2];
static if(X.length > 3) X[2] = X[3];
etc.

Nick



More information about the Digitalmars-d mailing list