problem with filter.
Andrea Fontana
nospam at example.com
Mon Mar 18 02:48:26 PDT 2013
On Monday, 18 March 2013 at 09:15:50 UTC, Knud Soerensen wrote:
>
>> First writeln() actually edit the original array, so when you
>> filter it
>> for the second array, fneg gives true for all clist[][][]
>> elements.
>
> How would you get around this ?
You should work on a whole copy of clist array.
Or return copy of elements from map function instead of the
element itself (<-- faster and lazy solution, i guess)
To get a whole copy you can try to do something like this:
T recursiveDup(T)(ref T array) if (isArray!T)
{
T retVal = array.dup;
foreach(ref e; retVal)
static if (isArray!(typeof(e)))
e = recursiveDup(e);
return retVal;
}
gives you a copy of your array. It's a simple code, that works
just for your specific case - not so efficient :)
More information about the Digitalmars-d-learn
mailing list