r/cpp • • Apr 24 '26

C++26: Structured Bindings can introduce a Pack

https://www.sandordargo.com/blog/2026/04/22/cpp26-structured-bindings-packs
101 Upvotes

40 comments sorted by

View all comments

Show parent comment

7

u/arades Apr 24 '26

The binding `auto [x, ...rest, z] = f();` is literally telling the compiler "I want the first and last item of whatever f() returns and _I don't care_ about the rest". If you actually care about the structure being returned this is just the wrong tool.

-1

u/Ateist Apr 25 '26

But the one who wrote it wanted first and last item that were in the original return type, not in the changed type.

The question is, does C++ need this "wrong tool"?

Does it bring enough value to justify bloating the standard with it, as well as numerous bugs that will appear out of abusing it?

Because people will misuse it if you let them.