Is the order of fields guaranteed returned by .tupleof
and __traits(getMember,...)
, can I rely on this? I know that are different things, I mean just per each use case if I have more functions that traverses through all fields. Thx.
Thread overview | |||||
---|---|---|---|---|---|
|
January 27, 2022 Order of object fields | ||||
---|---|---|---|---|
| ||||
January 27, 2022 Re: Order of object fields | ||||
---|---|---|---|---|
| ||||
Posted in reply to frame | On Thursday, 27 January 2022 at 12:45:20 UTC, frame wrote: >Is the order of fields guaranteed returned by Not for classes. The compiler is free to reorder if it wants to. Yes for structs. -Steve |
January 27, 2022 Re: Order of object fields | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 1/27/22 8:13 AM, Steven Schveighoffer wrote: >On Thursday, 27 January 2022 at 12:45:20 UTC, frame wrote: >Is the order of fields guaranteed returned by Not for classes. The compiler is free to reorder if it wants to. Yes for structs. To clarify, the compiler can reorder the members to fit them better. But it will be the same order for any particular build of the object files. Any compile-time features that fetch the members should be in the same order as the compiler has decided to lay them out. It's just that it might not match the source code order. -Steve |