On Monday, 8 August 2022 at 00:15:48 UTC, pascal111 wrote:
>On Sunday, 7 August 2022 at 23:44:26 UTC, Emanuele Torre wrote:
>On Sunday, 7 August 2022 at 23:31:45 UTC, pascal111 wrote:
>On Sunday, 7 August 2022 at 22:16:55 UTC, Emanuele Torre wrote:
>[...]
It seems complex, I didn't get it yet, I wished I didn't ask about it :)
It's really trivial.
auto [x, y] = getpoint();
is equivalent to
auto _p = getpoint();
auto x = _p.x /* first element of the struct */;
auto y = _p.y /* second element of the struct */;`
Also works with arrays.
int[] arr = { 10, 12, 14 };
const auto [x, y, z] = arr;
/* x=10 y=12 z=14 */
A lot of programming languages have this.
Really, I'm not sure I'm understanding this syntax auto [x, y] = getpoint();
, if you have the name of term of it in D or an explaining link.
D does not have it. You have already been told that when they have been mentioned.
If you want more information about it in C++, you could read https://en.cppreference.com/w/cpp/language/structured_binding or, for javascript, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment.
That was just meant to be a simple example to show what jfondren meant with "destructing bindings".