The D Blog is Back -- A Tale of Tuples

Vladimir Marchevsky vladimmi at gmail.com
Mon Apr 13 00:58:20 UTC 2026


> 2. Explicit Assignment: Manually declaring variables and 
> assigning them one by one.
> ...
> It’s verbose, it’s tedious, and it forces you to keep track of 
> a temporary variable (res) that you don’t even want.

Well, there is also a third way, half-way between the 
"Boilerplate hell" and that DIP, that avoids `res` variable:

```d
import std.meta;
import std.typecons;

Tuple!(int, string) getResult() {
     return tuple(404, "Not Found");
}

void main() {
     int code;
     string msg;
     AliasSeq!(code, msg) = getResult();
}
```

Having a way to both declare and assign in one statement looks 
great. Hopefully this DIP would be also implemented and merged 
quick enough to not get lost for years.


More information about the Digitalmars-d-announce mailing list