A different tuple syntax

bearophile bearophileHUGS at lycos.com
Thu May 30 05:32:45 PDT 2013


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


More information about the Digitalmars-d mailing list