Asssociative Array by Key-Value-Pair
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Dec 15 10:53:12 PST 2014
> One possible solution:
Another idea is to make "byPair" and "pairs" templates that by
default return 2-structs and use a Tuple on request (so you have
to import Phobos Tuple if you want them, so byPair doesn't depend
on Phobos and you can put in druntime):
int[string] aa;
assert(aa.byPair.array == aa.pairs);
byPair yields something like:
struct Pair { string key; value int; }
Now this yields tuples:
assert(aa.byPair!Tuple.array == aa.pairs!Tuple);
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list