TypeFunction example creatiing a conversion matrix

Andrei Alexandrescu SeeWebsiteForEmail at erdani.com
Thu Oct 1 18:10:05 UTC 2020


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.


More information about the Digitalmars-d mailing list