4 ms·
Tuples are ordered though. I don't usually think of structs by the order the properties are declared - I usually think of them by name. I am, admittedly, not p
by dvlsg 9y ago
Tuples are ordered though. I don't usually think of structs by the order the properties are declared - I usually think of them by name.
I am, admittedly, not primarily a c++ dev though. Are structs typically ordered data structures in c++?
- 21 9y agoThere is no struct here. x will be an independent variable which will take the first value from the tuple, and y the second one.
- euyyn 9y agoHis point is that it makes sense to destructure in order for tuples, but what makes sense for structs is destructuring by field name.
- jcelerier 9y ago> Tuples are ordered though. I don't usually think of structs by the order the properties are declared - I usually think of them by name. 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();
- nly 9y ago> I don't usually think of structs by the order the properties are declared 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