Bug 17201 – std.array: invert (convenience method that inverts a hashmap)

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-02-19T22:17:51Z
Last change time
2024-12-01T16:29:34Z
Assigned to
No Owner
Creator
Seb
Moved to GitHub: phobos#10236 →

Comments

Comment #0 by greeenify — 2017-02-19T22:17:51Z
This is often used and could potentially be implemented in a more performant way than the naive solution: auto invert(A)(A a) { import std.algorithm.iteration : map; import std.array; import std.typecons : tuple; auto a = [0:"a", 1:"b", 2:"c"]; return a.byKeyValue.map!(pair => tuple(pair.value, pair.key)).assocArray; }
Comment #1 by robert.schadek — 2024-12-01T16:29:34Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10236 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB