digitalmars.D.learn - Order of object fields
- frame (4/4) Jan 27 2022 Is the order of fields guaranteed returned by `.tupleof` and
- Steven Schveighoffer (4/8) Jan 27 2022 Not for classes. The compiler is free to reorder if it wants to.
- Steven Schveighoffer (7/16) Jan 27 2022 To clarify, the compiler can reorder the members to fit them better. But...
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.
Jan 27 2022
On Thursday, 27 January 2022 at 12:45:20 UTC, frame wrote: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.Not for classes. The compiler is free to reorder if it wants to. Yes for structs. -Steve
Jan 27 2022
On 1/27/22 8:13 AM, Steven Schveighoffer wrote:On Thursday, 27 January 2022 at 12:45:20 UTC, frame wrote: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. -SteveIs 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.Not for classes. The compiler is free to reorder if it wants to. Yes for structs.
Jan 27 2022