How to list aggregate members in order of declaration at compile time?

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Nov 11 15:55:58 PST 2016


On Friday, November 11, 2016 22:26:20 Ivan Kazmenko via Digitalmars-d-learn 
wrote:
> On Friday, 11 November 2016 at 22:04:37 UTC, Jonathan M Davis
>
> wrote:
> > ...
> >
> > I expect that it never occurred to Walter to specify that the
> > order of the members mattered with tupleof and that that's why
> > the spec doesn't say.
> >
> > So, use tupleof, and you can create an enhancement request in
> > bugzilla for the spec to be made clearer about it:
> > https://issues.dlang.org
>
> Thanks for the answer!  So you think the order guarantee is
> likely to be just granted for .tupleof if asked for.  I hope to
> get to creating a documentation issue/PR next week, to see more
> reaction.

I suspect so, but I don't know so. Certainly, it seems conceivable that
something dealing with structs and their layout would need to know the
order, and having tupleof have a guaranteed order would be the easiest
(though you could always look at each offset property individually and
figure it out). And if you really do need to be able to do something like
generate a constructor for a class based on the order of its member
declarations, then you need tupleof to give the order of declaration,
because the offset property won't necessarily match the order of declaration
for a class.

So, just provide a solid use case (if not multiple) as to why it needs to
have a specific order, and you probably stand a good chance of it being
added to the spec - especially since it's what the implementation does
anyway, and the implementation isn't likely to change. And given that
tupleof simply gives the member variables, I don't know of a good argument
for why it should ever do anything other than given them in the order that
they're declared.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list