Should be easy
Christopher Wright
dhasenan at gmail.com
Fri Jun 12 15:48:58 PDT 2009
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[] ignored...)
{
return element;
}
This uses template specialization to handle arrays differently than
non-arrays (that's what the "TArray : TArray[]" business means). It uses
the BaseType template worked out in one of your previous threads. It's
close enough to being the simplest thing that could work that I wouldn't
bother looking for anything simpler.
More information about the Digitalmars-d-learn
mailing list