Define an order for allMembers traits

Paul Backus snarwin at gmail.com
Wed Aug 23 18:32:44 UTC 2023


On Wednesday, 23 August 2023 at 16:28:27 UTC, Andrey Zherikov 
wrote:
> On Wednesday, 23 August 2023 at 15:32:02 UTC, Paul Backus wrote:
>> For this use case, you should use `.tupleof` instead of 
>> `__traits(allMembers)`, which [is guaranteed by the spec to 
>> give the fields in declaration order][1].
>>
>> [1]: https://dlang.org/spec/class.html#class_properties
>
> This link says "The order of the fields in the tuple matches 
> the order in which the fields are declared" for the classes. I 
> don't see such statement for structs 
> [here](https://dlang.org/spec/struct.html#struct_instance_properties).

The spec isn't totally clear, but I believe the intent is to say 
that it works the same way for structs unless otherwise stated. 
Certainly, in practice, the fields are always in declaration 
order.


More information about the Digitalmars-d mailing list