Should be easy
Christopher Wright
dhasenan at gmail.com
Sat Jun 13 05:38:44 PDT 2009
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:
void indexAssign(TArray : TArray[])(TArray array, BaseType!(TArray)
value, int[] indices...)
{
static if (is (typeof (array[0]) == typeof(value))
{
array[indices[0]] = value;
}
else
{
indexAssign(array[indices[0]], value, indices[1..$]);
}
}
> Also, why the ... ?
In case you know the number of indices ahead of time. It costs nothing
and lets you use a more natural syntax some of the time.
More information about the Digitalmars-d-learn
mailing list