Reimplementing the bulk of std.meta iteratively
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Sep 27 02:31:36 UTC 2020
On 9/26/20 8:27 PM, Adam D. Ruppe wrote:
> On Sunday, 27 September 2020 at 00:10:33 UTC, Stefan Koch wrote:
>> This example on the other hand works:
>
> Here's another potential implementation:
>
> ---
> template sortBySize(T...) {
[snip]
Sorting by inheritance relationship is more difficult. I got this going,
alpha quality:
https://gist.github.com/andralex/0d85df38be2d9ffbe89cf1fb51c44213
Now indeed calling std.sort against (reified) types just works.
The point is to reify the bases of the type as well so they can be
manipulated as objects. Then defining the comparison relation is easy
(didn't bother to make it efficient here - just a linear search).
More introspection-related matters would be reified the same way (store
during construction in the reified object, potentially via pointers if
they don't apply to all objects). Instance size would be an obvious
candidate, prolly I'll put it in there as a demo. More interestingly
we'd have things like parameters/return for functions and data members
for classes and structs. Long way ahead.
This is really exciting stuff.
More information about the Digitalmars-d
mailing list