.dup on an array of BitArray not duplicating
Chris Cain
clcain at uncg.edu
Tue May 15 13:44:15 PDT 2012
On Tuesday, 15 May 2012 at 20:26:12 UTC, ixid wrote:
> Sorry I made a typo in the second, it should be test2[0][0].
> I'm using std.bitmanip in D2.
Aha, I see! I'm somewhat surprised, normally I just use
Array!bool.
Well, you can look in the source to see some of how it works:
https://github.com/D-Programming-Language/phobos/blob/master/std/bitmanip.d#L475
So, when you call dup on the BitArray struct, it's duping the
payload pointer as well.
However, as I mentioned, duping a normal static array will not
"deep dup" everything.
You would have to do something like:
BitArray test[7];
foreach(ref i;test)
i.length = 7;
BitArray[7] test2;
foreach(i, ref e; test)
test2[i] = e.dup;
test2[0] = 1;
to get what you want done.
More information about the Digitalmars-d-learn
mailing list