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

10

u/jwakely libstdc++ tamer, LWG chair Apr 24 '26

Are you sure you know what "type safety" means?

Congratulation - you don't get ANY notification about the change.

How is the "bad" effect here any different from just writing:

auto x = f();

?!

In both cases you won't notice if the return type of f changes. So if that's a problem, don't use auto. Or add a static assert.

This has nothing to do with the feature you're moaning about.

If you don't like this feature in this specific use case, don't use it in this case. However you wrote your code today will still work after this feature is added, this feature didn't break anything, nobody killed your puppy.

1

u/Ateist Apr 25 '26

How is the "bad" effect here any different from just writing:

VERY different.

you won't notice if the return type of f changes

'x' exists not on its own but is processed later on.
So your call

g(x);  

is going to result in a compile error if the signature of the return type changes substantially.

In my example above this is not the case, because you are putting the value of z1 into y1 (let's assume they are the same type)