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