TypeFunction example: ImplictConvTargets

Stefan Koch uplink.coder at googlemail.com
Mon Oct 5 21:20:36 UTC 2020


On Monday, 5 October 2020 at 21:13:09 UTC, Paul Backus wrote:
> On Monday, 5 October 2020 at 20:57:04 UTC, Stefan Koch wrote:
>> On Monday, 5 October 2020 at 12:50:39 UTC, Andrei Alexandrescu 
>> wrote:
>>
>>> [...]
>>
>> This code does not work.
>> I don't even need to compile it to see that.
>
> It has some simple mistakes, but the fundamental idea is sound. 
> Here's a version that actually compiles:
>
> import std.meta;
>
> alias Numerics = AliasSeq!(byte, ubyte, short, ushort, int, 
> uint, long, ulong, float, double, real, char, wchar, dchar);
> enum convertsTo(T, U) = is(T : U);
> alias ImplicitConversionTargets(T) = 
> Filter!(ApplyLeft!(convertsTo, T), Numerics);
>
> // prints: (int, uint, long, ulong, float, double, real, dchar)
> pragma(msg, ImplicitConversionTargets!int);
> // prints: (float, double, real)
> pragma(msg, ImplicitConversionTargets!double);

Now post it with all transitive dependencies.
And we have a fair comparison.


More information about the Digitalmars-d mailing list