[Issue 20617] There is no support for copying hashmaps in Druntime / Phobos
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Jul 4 17:20:59 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=20617
Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|phobos |druntime
--- Comment #1 from Andrej Mitrovic <andrej.mitrovich at gmail.com> ---
Current workaround:
-----
import std.array;
import std.algorithm;
import std.typecons;
void main()
{
int[int] map1 = [1:1, 2:2, 3:3];
int[int] map2 = assocArray(map1.byKeyValue().map!(k => tuple(k.key,
k.value)));
}
-----
Notice that byKeyValue() does not return tuples, instead it returns 'Pair(...)'
structs, so these can't directly be passed to `assocArray`.
I suppose we could add an overload of `assocArray` that takes in `Pair()`s as
arguments, but that seems a bit "leaky" abstractions to me.
I'd rather we add an explicit 'duplicate' functionality to Druntime.
--
More information about the Digitalmars-d-bugs
mailing list