Genuine copy of an element from an associative array

Holzofen z5iph7ukvx at yopmail.com
Sun Oct 6 16:09:37 UTC 2024


On Sunday, 6 October 2024 at 10:53:28 UTC, Nick Treleaven wrote:
> On Thursday, 3 October 2024 at 12:23:27 UTC, Holzofen wrote:
>> [...]
>
>> Could anybody point me to a way how to make a straight copy 
>> without meddling with the source array?
>
> You can copy an AA using `dup`:
> https://dlang.org/phobos/object.html#.dup
>
> Unfortunately this doesn't work:
>
>     uint64[uint64] backup = factorials[n].dup;
>
> https://issues.dlang.org/show_bug.cgi?id=11725
>
> Instead you can use:
>
>     auto backup = cast(uint64[uint64]) factorials[n].dup;
>
> I think casting away const is OK because the AA produced by 
> `dup` is unique, and the element type doesn't have indirections.

Thanks a lot!


More information about the Digitalmars-d-learn mailing list