Tuple literal syntax
Juanjo Alvarez
juanjux at gmail.com
Thu Oct 7 05:24:16 PDT 2010
retard Wrote:
> Why do tuple fields need a name? Isn't this a new ad-hoc way to introduce
> structural typing in D? I often start with tuples, but if it turns out
> that the value is used in many places, it will be eventually replaced
> with a struct (e.g. coordinates in a gui / gamedev) for better type
> safety. Even with structs the need for field names is very rare. The real
> need for tuples is in very special cases where the syntax needs to be
> light.
I found they are useful for callbacks, when you can put, in a tuple, the delegate or function to the callback
and in another nested tuple the delegate/function parameters.
This way you can define the callbacks to be used along with their parameters, even if their signature is different.
You could do the same with the callbacks having variable number and types of args, using a template, but I like
this way more.
More information about the Digitalmars-d
mailing list