Thread overview
Structured binding declaration (like in C++)
4 days ago
Vindex
3 days ago
Ali Çehreli
3 days ago
Vindex
4 days ago

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;
3 days ago
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
3 days ago

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

3 days ago

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