On 12 January 2018 at 14:44, Timon Gehr via Digitalmars-d < digitalmars-d@puremagic.com> wrote:
> As promised [1], I have started setting up a DIP to improve tuple > ergonomics in D: > > https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md > > > This DIP aims to make code like the following valid D: > > --- > auto (a, b) = (1, 2); > (int a, int b) = (1, 2); > --- > > --- > foreach((sum, diff); [(1, 2), (4, 3)].map!((a, b) => (a + b, a - b))) > { > writeln(sum, " ", diff); > } > /+ prints: > 3 -1 > 7 1 > +/ > --- > > Before going ahead with it, I'd like some preliminary community input: > > - I'm not yet completely satisfied with the DIP. > (See section "Limitations".) > Please let me know suggestions or further concerns you might have. > > > - There are good example use cases missing. While I'm confident I could > invent a few of them given a little time, I thought maybe I can > expedite the process and make the point more convincingly by asking > for use cases you encountered in your own code. The DIP already > contains an example due to bearophile. > > > [1] https://forum.dlang.org/post/or625h$2hns$1...@digitalmars.com > This is nice work! I hope this is seriously considered. I'll add my 2c... You discuss 'auto unpacking', can you justify the value of this? I quite like C++ explicit unpacking (using ...), and I wouldn't be upset to see that appear here too. Explicit unpacking would solve your breaking change with auto unpacking, but the buggest advantage of C++'s '...' statement is that the unpack can involve expressions. auto t = (1, 2, 3); f(t...); // <-- regular expansion: f(1, 2, 3); f(arr[t]...); // <-- expression expansion: f(arr[1], arr[2], arr[3]); etc... It's amazingly useful to perform tuple expansion on an expression involving the tuple! So, why might implicit expansion be preferred to explicit expansion?