Thread overview
Structured binding declaration (like in C++)
Oct 13, 2021
Vindex
Oct 14, 2021
Ali Çehreli
Oct 14, 2021
MoonlightSentinel
Oct 14, 2021
Vindex
October 13, 2021

Is there a decomposition for tuples and other data structures?

For example,

auto t = tuple(1, "2");
auto (x, y) = t; // or auto (x, y) = t.expand;
October 14, 2021
On 10/13/21 1:02 PM, Vindex wrote:
> Is there a decomposition for tuples and other data structures?
> 
> For example,
> ```
> auto t = tuple(1, "2");
> auto (x, y) = t; // or auto (x, y) = t.expand;
> ```

No, D does not have this (yet?).

I thought there was a special case for tuples with foreach but I can't remember it now. (?)

Ali
October 14, 2021

On Wednesday, 13 October 2021 at 20:02:05 UTC, Vindex wrote:

>

Is there a decomposition for tuples and other data structures?

No, but you can emulate it, e.g. by using AliasSeq:

import std.meta : AliasSeq;
import std.typecons : tuple;
import std.stdio : writeln;

void main() {
    int a;
    string b;
    AliasSeq!(a, b) = tuple(1, "hello");

    writeln("a = ", a);
    writeln("b = ", b);
}

https://run.dlang.io/is/aUEtSK

October 14, 2021

On Thursday, 14 October 2021 at 15:29:13 UTC, MoonlightSentinel wrote:

>

On Wednesday, 13 October 2021 at 20:02:05 UTC, Vindex wrote:

>

Is there a decomposition for tuples and other data structures?

No, but you can emulate it, e.g. by using AliasSeq:

import std.meta : AliasSeq;
import std.typecons : tuple;
import std.stdio : writeln;

void main() {
    int a;
    string b;
    AliasSeq!(a, b) = tuple(1, "hello");

    writeln("a = ", a);
    writeln("b = ", b);
}

https://run.dlang.io/is/aUEtSK

Thank you! This is a good variant of decision of the problem