Reimplementing the bulk of std.meta iteratively

Stefan Koch uplink.coder at googlemail.com
Thu Oct 8 10:16:10 UTC 2020


On Thursday, 8 October 2020 at 09:44:33 UTC, Atila Neves wrote:
> On Thursday, 1 October 2020 at 02:49:43 UTC, Stefan Koch wrote:
>> On Wednesday, 30 September 2020 at 23:17:27 UTC, Timon Gehr 
>> wrote:
>>> On 29.09.20 01:37, Stefan Koch wrote:
>>>> [...]
>>>
>>> It's not a first-class type if you can't declare a variable 
>>> of that type. If this does not work, it's not first-class, 
>>> it's syntax sugar for reification:
>>>
>>> type t = int;
>>> auto f = (t x)=>x;
>>
>> Yes I do understand that.
>> I was wondering about practical usecases.
>
> import std.algorithm: filter, equal;
>
> type[] types = [int, uint, long, ulong];
> auto size4 = types.filter!(a => a.sizeof == 4);
> assert(equal(size4, [int, uint]));
>
> No more std.meta.Filter.
>
>> As far as I an aware, if I made the leap to first class types, 
>> that would make all usage of them into static polymorphism. 
>> (equivalent to templates)
>> And with that all the issues come back.
>
> I can't see how that's the case.

This is the correct type function way of doing it:
enum type[] types = makeTypeArray(int, uint, long, ulong);
enum type[] size4 = types.filter!((type a) => a.sizeof == 4);
static assert(equal!((type a, type b) => a is b) (size4, 
makeTypeArray(int, uint)));

Currently type[] fails is isInputRange though and therefore the 
phobos filter won't instantiate.
I am debugging this.


More information about the Digitalmars-d mailing list