struct S { int x1 : 2; volatile double y1; };
S f();
const auto [ x, y ] = f();
So it's just ordering based, I can't pull out one member by name? struct S { int x1 : 2; volatile double y1; };
S f();
const auto [ x, y ] = f();
So it's just ordering based, I can't pull out one member by name? const auto x = f().x1; > const {a, b} = {a: 'hey', b: 'there'}
undefined
> a
'hey'
> b
'there'Next version maybe they will even allow stuff like
[x, [y, z]] = f()
or [x, y, z...] = f()const auto [ x, y ] = make_tuple(1, 23);
I am, admittedly, not primarily a c++ dev though. Are structs typically ordered data structures in c++?
x will be an independent variable which will take the first value from the tuple, and y the second one.
Think for instance of a 2D point structure. There are tons of implementations, all with different naming conventions ; or sometimes storing them in an array. This allows to just do :
auto [x, y] = someRandomLibraryPoint();In C++ you have to, since it's guaranteed by the language that members are initialized in order of declaration (within the struct). And, like C of course, it also determines memory layout, padding and alignment
> Are structs typically ordered data structures in c++
Yes, and compilers like Clang even let you inspect their memory layout