Notes 5, GC performance

Janice Caron caron800 at googlemail.com
Wed Apr 16 23:55:16 PDT 2008


On 16/04/2008, bearophile <bearophileHUGS at lycos.com> wrote:
>  3) In thousands of functions/classes in my D libs I have code like the following; all those functions/classes scan/use keys of the given AAs (because an AA key is much more useful, with a key you can find the value, while with a value you generally can't quickly find the key).
>
>  static if (IsAA!(TyItems)) {
>   foreach (key, val; items) {
>     // key processing...
>   }
>  } else {
>   foreach (el; items) {
>     // el processing...
>   }
>  }
>
>  So far I haven't found a way to avoid such silly code duplication.

What's wrong with

    foreach (key, val; items) {...}

? That works for AAs, regular arrays, and any class which overloads
opApply with two variables.



More information about the Digitalmars-d mailing list