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))
> {
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]
>>> 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
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
> 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?
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
> 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
Ever heard of recursion?
Why don't you simply handle all types recursively? Why do you need this
"array depth" stuff?
> 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
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
>
> 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
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
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
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
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]],[],[],[],[],[],[],[
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.
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.
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
18 matches
Mail list logo