code generalization
Saaa
empty at needmail.com
Mon Jun 8 20:56:59 PDT 2009
"Christopher Wright" <dhasenan at gmail.com> wrote in message
news:h0kagg$13so$1 at digitalmars.com...
> Saaa wrote:
>> I just finished my array parser but I can't support just any depth
>> because each depth needs its own code the way I am doing it now :(
>
> Recursion?
> static if (is (U A : A[])) will give you int[] for int[][], so you can
> recursively call the parsing function with A as the type argument rather
> than U.
My attempt to rewrite the switch (failed : )
ddata\ddata.d(94): Error: slice expression array[] is not a modifiable
lvalue
ddata\ddata.d(169): template instance ddata.ddata.setLength!(int[]) error
instantiating
//an array depth walker :)
void setLength (T)( ref T array, int depth , int index)
{
if(depth > 0)
{
depth--;
setLength (array[], depth, index); //94
}
else
{
if(array.length < index) array.length = array.length * 2;
}
}
More information about the Digitalmars-d-learn
mailing list