Tuple DIP

Timon Gehr timon.gehr at gmx.ch
Sat Jan 13 14:15:48 UTC 2018


On 13.01.2018 03:08, jmh530 wrote:
> On Friday, 12 January 2018 at 22:44:48 UTC, Timon Gehr wrote:
>> As promised [1], I have started setting up a DIP to improve tuple 
>> ergonomics in D:
>> [snip]
> 
> I'm glad you're working on this.
> 
> Proposal 1 is a little terse in explaining what you mean by unpacking 
> AliasSeqs. You might explain it in a little more detail.
> ...

Will do. std.typecons.Tuple is a slightly more fancy version of the 
following:

struct Tuple(T...){
     T expand; // AliasSeq
     alias expand this; // inherits indexing/slicing etc.
     // with the proposal, also inherits unpacking
}


> Also, Proposal 1 starts with this example
> auto (a, b) = tuple(1, "2");
> (int a, string b) = tuple(1, "2");
> but it also looks natural to be able to write
> (int, string) (a, b) = tuple(1, "2");
> it looks from some of the other proposals that if they combine together 
> then this would also work.
> ...

Well, "auto" is not a placeholder type, but I'll think about it.

> Proposal 3 could use an example with named tuples.
> 
> In proposal 6, how does
> auto (a, _) = t;
> expand for multiple? Would you be forced to do
> auto (a, _, _, _, _, _) = t;
> if the tuple has 6 entries?

Yes and no. I'd imagine one would use

auto a = t[0];


More information about the Digitalmars-d mailing list