Associative array with duplicated keys?

cym13 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Nov 6 06:28:51 PST 2015


On Thursday, 5 November 2015 at 13:08:20 UTC, Adam D. Ruppe wrote:
> On Thursday, 5 November 2015 at 10:04:02 UTC, Andrea Fontana 
> wrote:
>> Anyway: are duplicated keys on declaration allowed?
>
> They shouldn't be...

Why? I'll admit it is something I've never even thought of using, 
but every language I know (just tested with python, lua, scheme 
and js) accepts it and as far as I can tell from a user 
perspective boils

     auto aa = ["a":10, "b", 42, "a":20];

down to:

      int[string] aa;
      aa["a"] = 10;
      aa["b"] = 42;
      aa["a"] = 20;

This is deterministic and could allow one to build an associative 
array through a mixin for example while still giving default 
values.

As I said, it's not something I've used but I think we should 
consider it.


More information about the Digitalmars-d-learn mailing list