Reimplementing the bulk of std.meta iteratively
Sebastiaan Koppe
mail at skoppe.eu
Thu Oct 8 14:19:41 UTC 2020
On Thursday, 8 October 2020 at 10:16:10 UTC, Stefan Koch wrote:
> 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.
This is plain awesome.
The fact that it reuses the filter algorithm is a sign that both
filter and type functions are correctly designed.
Who could ever imagined that a template would be instantiated
with a lambda that takes a type-value as an argument. WAT!? That
is some high-order stuff, and perfectly readable.
Andrei's de/reify is awesome as well, it has the advantage of
working with existing language constructs, but it isn't as simple.
More information about the Digitalmars-d
mailing list