Is there kind of "associative tuple" - like syntax in D?

Uranuz neuranuz at gmail.com
Fri Feb 21 11:09:56 PST 2014


>
> You could do something like this:
>
> alias Foo!(
>     OptionType.optType1, 100,
>     OptionType.optType2, "example,
>     ...etc...
> ) MyFoo;

Yes. I already use this. But it makes it not semanticaly obvious 
that OptionType.optType1 is a kind of `key` and 100 is `value`. 
Also it needs to parse it and check for correctness that you have 
`key` and corresponding value. Also code that realize parsing 
could shadow main logic of class/function. Another point is that  
`key`: `value` form is easier to read than sequence of some 
values separated by ','. You often need to move every key-value 
pair to single line to make it readeble.

May be it's just syntactic sugar and isn't looking in D'ish way 
or something.



More information about the Digitalmars-d-learn mailing list