Tuple deconstruction in Phobos

IchorDev zxinsworld at gmail.com
Sun Jul 21 04:05:52 UTC 2024


On Saturday, 20 July 2024 at 20:48:29 UTC, Nick Treleaven wrote:
> Instead of the `tie` assignment, you can just do:
> ```d
> 	import std.meta;
> 	AliasSeq!(y, x) = tupRetFn().expand;
> ```

And here I was trying to use comma expressions for this like a 
buffoon! Of course they didn't work, but I'm pleasantly surprised 
that using a sequence does. I should really PR `std.typecons` to 
add a couple of examples of this, because I think a lot of people 
will have overlooked it.
I honestly thought there was no way to do this in D for the 
longest time until I saw some C++ code using `std::tie` and I 
realised that obviously the same thing is doable in D using 
`opAssign`, and then refined it to use UFCS because the syntax 
`Tie!(y,x)()` was a bit clunky.


More information about the Digitalmars-d-learn mailing list