A different tuple syntax

bearophile bearophileHUGS at lycos.com
Thu May 30 08:07:45 PDT 2013


Diggory:

> Could also do something in the style of token strings, ie.
>
> t{ ... }

It's less noisy than @{} or ${}:

auto t = t{}; // empty.
@[10] t{int, string} tup = t{1, "hi"}; // With UDA.
foreach (Float; t{float, double, real}) { ... }
auto t{x, y} = t{1, "hi"};
t{auto x, y} = t{1, "hi"};
t{int x, string y} = t{1, "hi"};
foreach (i, const t{x, y}; [t{1,2}, t{3,4}, t{5,6}, ...]) {
void foo(t{int, string name}, string msg);
(t{A a, B b}) => a + b;
switch (tup) { case t{1, 2}: ... }

Bye,
bearophile


More information about the Digitalmars-d mailing list