Re: Should be easy

2009-06-16 Thread Saaa
template BaseType(T: T[]) { alias BaseType!(T) BaseType; } template BaseType(T) { alias T BaseType; } > Otherwise, you need indexAssign: > > void indexAssign(TArray : TArray[])(TArray array, BaseType!(TArray) value, > int[] indices...) > { > static if (is (typeof (array[0]) == typeof(value)) > {

Re: Should be easy

2009-06-15 Thread BCS
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]

Re: Should be easy

2009-06-15 Thread 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 I

Re: Should be easy

2009-06-14 Thread BCS
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

Re: Should be easy

2009-06-14 Thread 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?

Re: Should be easy

2009-06-13 Thread Christopher Wright
Saaa wrote: I did get it to compile at one time, but didn't know how to use it, like your code.. index( array, index2); //compiles and all, but how do I set the value? index( array, index2) = -1; // doesn't work If you're using d2, add 'ref' to the return type. Otherwise, you need indexAssign

Re: Should be easy

2009-06-12 Thread Saaa
> Ever heard of recursion? > > Why don't you simply handle all types recursively? Why do you need this > "array depth" stuff? Most probably because I tackle my parsing problem sub-optimally. This is how I do it: load file into char[][] create: int[][][] arr; call: ddata.get( (in) file, (in) 'ar

Re: Should be easy

2009-06-12 Thread grauzone
Ever heard of recursion? Why don't you simply handle all types recursively? Why do you need this "array depth" stuff?

Re: Should be easy

2009-06-12 Thread Saaa
> Saaa wrote: >> I can't figure out how to create the IndexArray function, >> it should work on arrays of any depth > > BaseType!(TArray) index(TArray : TArray[])(TArray array, int[] indices...) > { > return index(array[indices[0]], indices[1..$]); > } > > TElement index(TElement)(TElement element

Re: Should be easy

2009-06-12 Thread Denis Koroskin
On Sat, 13 Jun 2009 03:37:59 +0400, Saaa wrote: IndexArray should take an array of integers as well. The int[] foo... syntax is implicit "convert to array" anyway. I think I'll go with Christophers code, hope you don't mind :) Also, please bottom-post. It's the convention. :) Why is th

Re: Should be easy

2009-06-12 Thread Saaa
> > IndexArray should take an array of integers as well. The int[] foo... > syntax is implicit "convert to array" anyway. I think I'll go with Christophers code, hope you don't mind :) > > Also, please bottom-post. It's the convention. > > :) Why is that? scroll scroll I probably use a retarded

Re: Should be easy

2009-06-12 Thread Christopher Wright
Saaa wrote: I can't figure out how to create the IndexArray function, it should work on arrays of any depth BaseType!(TArray) index(TArray : TArray[])(TArray array, int[] indices...) { return index(array[indices[0]], indices[1..$]); } TElement index(TElement)(TElement element, int[] ig

Re: Should be easy

2009-06-12 Thread downs
Saaa wrote: > Thanks! > I thought about the idea of just creating the code and mix it in, but now I > can see why I failed at that: Your code is kind of read-only to me, for now, > because I need to change it a bit to accept an array instead of seperat > indices. > > Wouldn't it be nice if it w

Re: Should be easy

2009-06-12 Thread Saaa
Thanks! I thought about the idea of just creating the code and mix it in, but now I can see why I failed at that: Your code is kind of read-only to me, for now, because I need to change it a bit to accept an array instead of seperat indices. Wouldn't it be nice if it worked like this: int[] ind

Re: Should be easy

2009-06-12 Thread downs
Saaa wrote: > 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]],[],[],[],[],[],[],[

Re: Should be easy

2009-06-12 Thread Saaa
Thanks. But my problem lays in supporting arrays of arbitrary depth. > For 2 dim array I like "auto a=new char[][](40,25);" so that > "a[39][24]='B';" 'B' is at the bottom right of the 2D array.

Re: Should be easy

2009-06-12 Thread Joel Christensen
For 2 dim array I like "auto a=new char[][](40,25);" so that "a[39][24]='B';" 'B' is at the bottom right of the 2D array.

Should be easy

2009-06-12 Thread Saaa
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