Reimplementing the bulk of std.meta iteratively

Stefan Koch uplink.coder at googlemail.com
Thu Oct 8 09:51:28 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.

What you just described is what type functions do.
The point that with first class type you could do also this:

// cat type_list.txt: 'int, uint, long, ulong';
auto type_txt = readText("type_list.txt");
type[] types = type_txt.parseTypes()
auto size4 = types.filter!(a => a.sizeof == 4);
assert(equal(size4, [int, uint]));
type[0] myVar1;
type[1] myVar2;



More information about the Digitalmars-d mailing list