Tuple DIP

aliak something at something.com
Tue Jan 16 21:03:40 UTC 2018


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:
>
> https://github.com/tgehr/DIPs/blob/tuple-syntax/DIPs/DIP1xxx-tg.md
> ...
>

Oh Yes!

Question, would named tuples be able to be worked in or is that 
way out of scope? I.e. something for this use case:

alias Color = Tuple!(int, "r", int, "g", int, "b");
Color f(Color input);
auto color = f(Color(1, 2, 3));
writeln(color.r);

Very handy with general graphics stuff, Point, Vector, etc

Or for getting enumerate type functionality?
range.enumerate() // Tuple!(int, "index", T, "value)

So would we be able to work in something like:

(r: int, g: int, b: int) f(int r, int g, int b) {
     return (100, 200, 150);
}

// Or more consistent with function syntax?
(int r, int g, int b) f(int r, int g, int b) {
     return (100, 200, 150);
}

// And how about auto return named tuples?
auto f(int r, int g, int b) {
     return (r: 100, g: 200, z: 150);
}






More information about the Digitalmars-d mailing list