Should be easy

Saaa empty at needmail.com
Mon Jun 15 03:33:22 PDT 2009


>>> Ever heard of recursion?
>>>
>>> Why don't you simply handle all types recursively?
>>>
>> I'm still very interested in what exactly that means. Could you maybe
>> give a small example?
>>
>
> int Index(T)(T arr, int[] ind)
> {
>  static if(is(T B == B[][])) // if array of array
>      return Index!(B[])(arr[ind[0]], ind[1..$]);
>  else
>  {
>      static assert(is(T B == B[])); // had better be an array;
>      return arr[ind[0]];
>  }
> }
>
> void main()
> {
>    int[][][] d;
>    d.length = 3;
>    d[1].length = 3;
>    d[1][2].length = 3;
>    d[1][2] = [0,1,1];
>
>    assert(0==Index!(int[][][])(d,[1,2,0]));
> }
>
Thanks,
but how does this differ from what Christopher Wright suggested? 




More information about the Digitalmars-d-learn mailing list