TypeFunction example: ImplictConvTargets
Stefan Koch
uplink.coder at googlemail.com
Tue Oct 6 03:50:11 UTC 2020
On Tuesday, 6 October 2020 at 00:25:40 UTC, foobar wrote:
> On Monday, 5 October 2020 at 21:20:36 UTC, Stefan Koch wrote:
>> 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.
>
> Post your code with all changes to the language and compiler.
> Then we have a fair comparison.
Actually no.
The compiler changes don't affect the user.
They're for a small number of people to know about and support.
Typefunctions and CTFE are together still much less complicated
than the template system is.
I have nothing to hide though here it is
https://github.com/dlang/dmd/compare/master...UplinkCoder:talias_master
650 lines of rather clean code which can in the future be
factored with the respective semantic routines.
More information about the Digitalmars-d
mailing list