Type functions with std.algorithm
Petar
Petar
Sun Oct 11 06:22:26 UTC 2020
On Sunday, 11 October 2020 at 00:46:37 UTC, Stefan Koch wrote:
> The code below here works with the current talias_master branch!
>
> alias type = __type;
>
> type[] makeTypeArray(type[] types ...)
> {
> return types;
> }
>
> import std.algorithm;
>
> enum type[] types = makeTypeArray(int, uint, long, ulong);
> enum size4 = types.filter!((type a) { return a.sizeof == 4; } );
> pragma(msg, () {
> type[] result = [];
> foreach(t;size4)
> {
> result ~= t;
> }
> return result;
> }().tupleof);
> // outputs: tuple((int), (uint))
Nice!
Is there an issue with `std.array.array`, or you just prefer
manually converting the range to an array? Btw, dmd can evaluate
ranges at compile-time (e.g. in static foreach), so .tupleof
could potentially also do that (convert both ranges and arrays of
types to a tuples).
More information about the Digitalmars-d
mailing list