Tuples a first class feature, manu's new unary operator and named arguments

Jacob Carlborg doob at me.com
Sat May 9 06:37:18 UTC 2020


On 2020-05-09 05:04, Walter Bright wrote:

> Keep in mind that as of recently, AliasSeq!(1,2,3) generates a tuple 
> directly without going through the template instantiation mechanism.

For first class support for tuples it would be really nice to support 
named elements in the tuple: `(foo: 1, bar: 2, baz: 3)`, which 
`AliasSeq` does not support.

This could also be used to solve the major complaint about removing the 
struct static initialization syntax.

struct Point
{
     int x;
     int y;
}

Today:

Point a = { x: 3, y: 4 };

With first class tuples with named elements:

auto b = (x: 3, y: 4);
static assert(is(typeof(a) == (int, int));

Point c = (x: 3, y: 4);
Point d = b; // possibly allow this

For this small example it might not matter but there are bigger examples 
[1].

[1] https://forum.dlang.org/post/aqgvlgpjbwdhrxuoezjs@forum.dlang.org

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list