A Discussion of Tuple Syntax

Timon Gehr timon.gehr at gmx.ch
Mon Aug 19 23:39:04 PDT 2013


On 08/20/2013 02:18 AM, Andrei Alexandrescu wrote:
>
> Why would it be necessary to return an object of type TypeTuple (i.e.
> template tuple)?


- Elegance. Eg:

auto seq(T...)(T arg){ return arg; }

auto fold(alias a,S,R)(S start, R range){ ... }


seq(0,[1,2,3]).fold!((a,b)=>a+b);


(Obviously you can get close by requiring expansion at the call site.)


- ABI

Multiple return values could use a more efficient ABI than struct 
instances because they do not have an address.


- Consistency

A type whose instances cannot be returned from a function is just weird 
language design.


> It has no state.

It may alias variables that do.


More information about the Digitalmars-d mailing list