Should be easy

Saaa empty at needmail.com
Fri Jun 12 00:57:01 PDT 2009


I can't figure out how to create the IndexArray function,
it should work on arrays of any depth

int[][][] array; //any depth
array.length=10;
array[1].length=3;
array[1][2].length=4;
array[1][2][1]=99;

writefln(array);
//[[],[[],[],[0,99,0,0]],[],[],[],[],[],[],[],[]]

int[3] index; //same length as depth
index[0]=1;
index[1]=2;
index[2]=3;

IndexArray( array, index) = -1;
//equal to :
//array[ index[0] ][ index[1] ][ index[2] ] = -1;

writefln(array);
//[[],[[],[],[0,99,0,-1]],[],[],[],[],[],[],[],[]]

All suggestions are greatly appreciated !





More information about the Digitalmars-d-learn mailing list