Reimplementing the bulk of std.meta iteratively

Bruce Carneal bcarneal at gmail.com
Sun Sep 27 03:46:52 UTC 2020


On Sunday, 27 September 2020 at 02:31:36 UTC, Andrei Alexandrescu 
wrote:
> 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.

We're in an early stage of exploration of discovered capability, 
so I understand the excitement.  The C++ guys must have been way 
excited about their meta programming discoveries as well.

Just a respectful reminder here: a discovered way to do something 
is not a designed way to do something.  Cleverness can take you a 
very very long way (Modern C++ anyone? :-) ) but it's unlikely 
that it will take you to appropriate simplicity.

Whatever decisions are made down the road, I'm happy that we're 
actively looking at extending D's safely accessible meta 
programming capabilites now.  Sounds like a great topic for 
beerconf-day-2.















More information about the Digitalmars-d mailing list