Variant associative arrays
bearophile
bearophileHUGS at lycos.com
Wed May 8 17:33:08 PDT 2013
Byron Heads:
> I have a variant associative array. In the example below I am
> wondering
> if there is a way to create the array without having to
> indicate the
> variant type on all of the values. Would like to be able to
> write code
> like #2, or something cleaner/better for #1.
> ...
> // #1 This works
> foo(["first" : HDType("John"),
> "last" : HDType("Doe"),
> "phone" : HDType(1234546)]);
>
> // #2 Wont compile, type mismatch string and long
> foo(["first" : "John",
> "last" : "Doe",
> "phone" : 1234546]);
If your purpose is to write such associative literal without
repeating the HDType(), then a possibility is to write the data
in a single string, and feed it to a compile-time function that
splits it and builds the associative array.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list