Thread overview | |||||
---|---|---|---|---|---|
|
October 20, 2016 Reflection: Order of fields guaranteed? | ||||
---|---|---|---|---|
| ||||
When using reflection to obtain the fields of a class/struct, is there any guarantee that the order is the same as the order the fields are defined? |
October 21, 2016 Re: Reflection: Order of fields guaranteed? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | On Friday, 21 October 2016 at 01:34:44 UTC, Nick Sabalausky wrote:
> When using reflection to obtain the fields of a class/struct, is there any guarantee that the order is the same as the order the fields are defined?
Yes they should always come in lexical order.
|
October 22, 2016 Re: Reflection: Order of fields guaranteed? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stefan Koch | On Friday, 21 October 2016 at 01:51:44 UTC, Stefan Koch wrote: > On Friday, 21 October 2016 at 01:34:44 UTC, Nick Sabalausky wrote: >> When using reflection to obtain the fields of a class/struct, is there any guarantee that the order is the same as the order the fields are defined? > > Yes they should always come in lexical order. For classes, the spec disagrees, even though it might be true using current compilers. https://dlang.org/spec/class.html#fields "The D compiler is free to rearrange the order of fields in a class to optimally pack them in an implementation-defined manner. ... Explicit control of field layout is provided by struct/union types, not classes." |
Copyright © 1999-2021 by the D Language Foundation