A different tuple syntax

js.mdnq js_adddot+mdng at gmail.com
Thu May 30 14:40:45 PDT 2013


On Thursday, 30 May 2013 at 12:32:46 UTC, bearophile wrote:
> If you don't like to introduce a new keyword, then a different 
> alternative is to use the @ again, a bit like UDAs:
>
> @{...}
>
> @[10] @{int, string} tup = @{1, "hi"}; // With UDA.
> foreach (Float; @{float, double, real}) { ... }
> auto @{x, y} = @{1, "hi"};
> @{auto x, y} = @{1, "hi"};
> @{int x, string y} = @{1, "hi"};
> foreach (i, const @{x, y}; [@{1,2}, @{3,4}, @{5,6}, ...]) {
> void foo(@{int, string name}, string msg);
> (@{A a, B b}) => a + b;
> switch (tup) { case @{1, 2}: ... }
>
> Bye,
> bearophile

Or rather # or & as they do have some inherent relation to 
tuples..

#(int, string) tup
&(int, string) tup

The second remind one it is a sort of concatenation of types. 
e.g., int & string.


More information about the Digitalmars-d mailing list