|Posted by Ameer Armaly||PermalinkReply|
Here is a little template I wrote to create an AA given an array of keys and
an array of values. It's put in the public domain, so if you have a use for
it, go ahead. I'm relatively new to templates, so if I've missed something
let me know; it seems to check out fine.
// Array maker template.
// Written by Ameer Armaly and placed in to the public domain.
class MakeAAException: Exception
template makeAA(Tk, Tv)
// Tk is the key type, Tv is the value type
Tv[Tk] makeAA(Tk keys, Tv values)
// There have to be the same number of keys as values.
if(keys.length != values.length)
throw new MakeAAException("The number of keys and values do not
foreach(i, v; values)
AA[keys[i]] = v;