unordered output of an associated array of associated arrays

forkit forkit at gmail.com
Tue Jan 25 00:39:16 UTC 2022


On Tuesday, 25 January 2022 at 00:23:40 UTC, forkit wrote:
>
another example:

output is:
typeA:
	100000001:[0, 0, 1, 1, 1, 1, 1, 1]
	100000002:[0, 0, 0, 1, 1, 1, 1, 1]
typeB:
	100000005:[0, 0, 0, 0, 0, 0, 1, 1]
	100000003:[0, 0, 0, 0, 1, 1, 1, 1]
	100000004:[0, 0, 0, 0, 0, 1, 1, 1]


// --

module test;

import std;

void main()
{
     auto aaTable2 =
       ([
        "typeA" : [ 100000001 : [0, 0, 1, 1, 1, 1, 1, 1],
                    100000002 : [0, 0, 0, 1, 1, 1, 1, 1] ],
        "typeB" : [ 100000003 : [0, 0, 0, 0, 1, 1, 1, 1],
                    100000004 : [0, 0, 0, 0, 0, 1, 1, 1],
                    100000005 : [0, 0, 0, 0, 0, 0, 1, 1] ]
                  ]);

     foreach (topLevelKey, topLevelValue; aaTable2.byPair)
     {
         writefln("%s:", topLevelKey);

         foreach(key, value; topLevelValue)
         {
             writefln("\t%s:%s", key, value);
         }
     }

}

//--





More information about the Digitalmars-d-learn mailing list