Best way to duplicate an associative array

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Mar 23 07:41:41 PST 2006


"Jarrett Billingsley" <kb3ctd2 at yahoo.com> wrote in message 
news:dvuba7$196f$1 at digitaldaemon.com...

Actually, this is simpler and may be faster (not sure):

template dup(T)
{
 T dup(T aa)
 {
  T aa2;

  foreach(key, value; aa)
   aa2[key] = value;

  return aa2;
 }
}

void main()
{
 int[char[]] aa;
 aa["hello"] = 5;
 aa["fork"] = 10;

 int[char[]] aa2 = aa.dup();

 foreach(char[] key, int value; aa)
  writefln(key, ": ", value);

 writefln();

 foreach(char[] key, int value; aa2)
  writefln(key, ": ", value);
} 





More information about the Digitalmars-d mailing list