Thread overview
[Issue 18426] Conversion from Tuple with named fields to Tuple without named fields should work during compilation
Feb 12, 2018
Seb
Feb 12, 2018
Seb
Dec 17, 2022
Iain Buclaw
Dec 16, 2023
Basile-z
February 12, 2018
https://issues.dlang.org/show_bug.cgi?id=18426

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|nobody@puremagic.com        |greensunny12@gmail.com

--
February 12, 2018
https://issues.dlang.org/show_bug.cgi?id=18426

--- Comment #1 from Seb <greensunny12@gmail.com> ---
A minimal testcase

---
alias point = Tuple!(int, "x",  int, "y");
static assert(point(2, 2)[0] == 0);
---

--
February 12, 2018
https://issues.dlang.org/show_bug.cgi?id=18426

--- Comment #2 from Seb <greensunny12@gmail.com> ---
And a stripped down version of std.typecons.Tuple:

https://gist.github.com/wilzbach/0a55a571f1c46e9d59420cf158354b85

> A better implementation would be to have the Tuple with named fields use the Tuple with no named fields as its only member variable; then, "alias this" needs to simply return a reference to that member.

This is already done:


struct Tuple
{
   Types expand; // e.g. AliasSeq!(int, int)
}


However, if `alias expand this` is used, this stops to work:

---
auto t1 = Tuple!(int, "x", string, "y")(1, "a");
void foo(Tuple!(int, string) t2) {}
foo(t1);
---

foo.d(149): Error: function foo.__unittest_L143_C7.foo(Tuple!(int, string) t2)
is not callable using argument types (Tuple!(int, "x", string, "y"))
foo.d(149):        cannot pass argument t1 of type Tuple!(int, "x", string,
"y") to parameter Tuple!(int, string) t2

--
February 12, 2018
https://issues.dlang.org/show_bug.cgi?id=18426

--- Comment #3 from Andrei Alexandrescu <andrei@erdani.com> ---
(In reply to Seb from comment #2)
> And a stripped down version of std.typecons.Tuple:
> 
> https://gist.github.com/wilzbach/0a55a571f1c46e9d59420cf158354b85
> 
> > A better implementation would be to have the Tuple with named fields use the Tuple with no named fields as its only member variable; then, "alias this" needs to simply return a reference to that member.
> 
> This is already done:

Nonono, we need to do this:

Tuple!(int, "x", int, "y") should have as its only state Tuple!(int, int). In
the form of a data member that is. Call that field impl. Then:

alias impl this;

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=18426

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--
December 16, 2023
https://issues.dlang.org/show_bug.cgi?id=18426

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|dmd                         |phobos

--