[Issue 2173] New: foreach iteration not possible for associative array indexed with static array

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jun 25 09:38:20 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2173

           Summary: foreach iteration not possible for associative array
                    indexed with static array
           Product: D
           Version: 1.031
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: georg at op-co.de


Trying to foreach through an AA[SA] generates a compiler error:

import std.stdio;
import std.md5;
int main(char[][] args) {
        int[ubyte[16]] md5count;
        foreach (md5, count; md5count)
                writefln("%s: %d", std.md5.digestToString(md5), count);
        return 0;
}

Both gdc and dmd bail out on the foreach statement with:
"test.d(5): Error: cannot have out or ref parameter of type ubyte[16u]"

Possible workarounds:
 * use a wrapper struct for the static array (looks ugly)
 * use foreach (md5; md5count.keys) ... count = md5count[md5]
      (decreases performance almost by 50%)


-- 



More information about the Digitalmars-d-bugs mailing list