A Discussion of Tuple Syntax

deadalnix deadalnix at gmail.com
Mon Aug 19 22:29:40 PDT 2013


On Monday, 19 August 2013 at 21:03:50 UTC, Andrei Alexandrescu 
wrote:
> I'm saying that there's a mix of useful stuff and just 
> syntactic additions that are arguably less so. In my opinion:
>
> a) destructuring tuples in auto declarations - good to have:
>
> auto (a, b, c) = 
> functionReturningTupleOrStaticArrayWith3Elements();
>

I propose the following rewrite :

auto tmp = functionReturningTupleOrStaticArrayWith3Elements();
assert(tmp.length == 3);
auto a = tmp[0];
auto b = tmp[1];
auto c = tmp[2];

That way any type user can take advantage of the new syntax, and 
it is easy to implement as it is simple rewrite rules. Note that 
tmp do not need to be an lvalue to avoid uneeded copies.

I'd also like to see the term Tuple for variadic template 
parameter go away. This is confusing the hell out of everybody, 
as the current conversation is showing.


More information about the Digitalmars-d mailing list