digitalmars.D.learn - Structured binding declaration (like in C++)
- Vindex (6/6) Oct 13 2021 Is there a decomposition for tuples and other data structures?
- =?UTF-8?Q?Ali_=c3=87ehreli?= (5/12) Oct 14 2021 No, D does not have this (yet?).
- MoonlightSentinel (15/16) Oct 14 2021 No, but you can emulate it, e.g. by using AliasSeq:
- Vindex (3/19) Oct 14 2021 Thank you! This is a good variant of decision of the problem
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; ```
Oct 13 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
Oct 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: ```d 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
Oct 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:Thank you! This is a good variant of decision of the problemIs there a decomposition for tuples and other data structures?No, but you can emulate it, e.g. by using AliasSeq: ```d 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
Oct 14 2021