TypeFunction example creatiing a conversion matrix
Stefan Koch
uplink.coder at gmail.com
Thu Oct 1 18:19:15 UTC 2020
On Thursday, 1 October 2020 at 18:10:05 UTC, Andrei Alexandrescu
wrote:
> On 10/1/20 1:55 PM, Stefan Koch wrote:
>> On Thursday, 1 October 2020 at 17:50:39 UTC, Andrei
>> Alexandrescu wrote:
>>> On 10/1/20 1:45 PM, Stefan Koch wrote:
>>>> On Thursday, 1 October 2020 at 17:35:51 UTC, Andrei
>>>> Alexandrescu wrote:
>>>>> On 10/1/20 1:26 PM, Steven Schveighoffer wrote:
>>>>>> [...]
>>>>>
>>>>> How do you implement Variant.get(T) without reifying is(T :
>>>>> U)?
>>>>
>>>> What does it do?
>>>> is Variant.get returning type T ?
>>>
>>> Yes: https://dlang.org/phobos/std_variant.html#.VariantN.get
>>>
>>>> Then I would assume you don't.
>>>> You use a template + typeid that's what they are for!
>>>>
>>>> Variant.get is not doing any type computation which you
>>>> would need is (T : U) for?
>>>> Where would I use it?
>>>
>>> Everywhere Variant.get is called. The decision is(T : U)
>>> needs to be carried, except that one of the types is
>>> available only at runtime.
>>
>> Please show me in the code where is(T : U) is used.
>> I don't find it in std variant.
>
> It's in the use of ImplicitConversionTargets in std.traits. If
> I remember correctly that template was created exactly to help
> with implementing Variant. It does an incomplete and in places
> incorrect job at figuring out what implicit conversions would
> work. That information is saved as part of the pointer to
> function stored in the Variant object, and used to figure out
> if the call to get() is valid.
So if your question is could you implement
'ImplicitConversionTargets' as a type function the answer is most
likely yes.
I haven't looked at the code too deeply.
But it should work in principle if it doesn't it's an
implementation bug.
As such this 'ImplicitConversionTargets' is indeed a good
use-case to look at.
More information about the Digitalmars-d
mailing list