Should be easy

BCS none at anon.com
Mon Jun 15 09:30:14 PDT 2009


Hello Saaa,

>>>> 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?

I don't know if it does, it is a direct answer to your question: "Could you 
maybe give a small example?"

This code is an example of what handling all (array) types recursively means.




More information about the Digitalmars-d-learn mailing list