On 6/2/21 11:32 AM, Sean wrote:
Is this normal behavior of dup? if so, how can I get the behavior i am
searching for? Thank you.
Yes. `dup` is a shallow copy.
To get the behavior you want:
```d
auto deepdup(T)(T[] arr)
{
import std.algorithm, std.array;
static if(is(T == U[], U))
return arr.map!(x => .deepdup(x)).array;
else
return arr.dup;
}
// use like arr.deepdup where you would normally put arr.dup
```
Note that this is going to be pretty inefficient allocation-wise, but
will work with minimal code.
-Steve