std.jgrandson

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sun Aug 3 12:35:42 PDT 2014


On 8/3/14, 11:08 AM, Johannes Pfau wrote:
> Am Sun, 03 Aug 2014 09:17:57 -0700
> schrieb Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org>:
>
>> On 8/3/14, 8:51 AM, Johannes Pfau wrote:
>>>
>>> Variant uses TypeInfo internally, right?
>>
>> No.
>>
>
> https://github.com/D-Programming-Language/phobos/blob/master/std/variant.d#L210

That's a query for the TypeInfo.

> https://github.com/D-Programming-Language/phobos/blob/master/std/variant.d#L371

That could be translated to a comparison of pointers to functions.

> https://github.com/D-Programming-Language/phobos/blob/master/std/variant.d#L696

That, too, could be translated to a comparison of pointers to functions.

It's a confision Let me clarify this. What Variant does is to use 
pointers to functions instead of integers. The space overhead (one word) 
is generally the same due to alignment issues.

> Also the handler function concept will always have more overhead than a
> simple tagged union. It is certainly useful if you want to store any
> type, but if you only want a limited set of types there are more
> efficient implementations.

I'm not sure at all actually. The way I see it a pointer to a function 
offers most everything an integer does, plus universal functionality by 
actually calling the function. What it doesn't offer is ordering of 
small integers, but that can be easily arranged at a small cost.


Andrei



More information about the Digitalmars-d mailing list