First Draft: Tuple Unpacking Syntax
IchorDev
zxinsworld at gmail.com
Thu Jul 31 11:46:17 UTC 2025
On Friday, 25 July 2025 at 04:27:53 UTC, Meta wrote:
>
> The DIP:
> https://github.com/MetaLang/DIPs/blob/bf357d16b1bce65ba4ed95a08d146d4015eeb2d7/DIPs/1NNN-JH-TG-NT.md
> [...]
> Moving elements (rather than copying) from the value sequence
> is not supported.
Could you please add an explanation for this? I really don't
understand why it wouldn't be supported, and I would certainly
prefer for unpacking to be a move rather than a copy in general.
> ## Postponed: Unpacking assignments
> Unpacking a tuple into lvalues is postponed until tuple
> literals are supported, because both redefine the comma
> operator syntax.
> ```d
> auto t = (1, 2); // tuple literal
> int x, y;
> (x, y) = t;
> assert(x == 1);
> assert(y == 2);
> ```
You can pretty-much already do this like so:
```d
int x, y;
AliasSeq!(x, y) = t;
```
More information about the dip.development
mailing list