Objective-D, reflective programming, dynamic typing
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Apr 5 09:44:30 PDT 2009
dsimcha wrote:
> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
>> Christopher Wright wrote:
>>> Andrei Alexandrescu wrote:
>>>> Christopher Wright wrote:
>>>>> What information did you find that you needed but is not available in
>>>>> TypeInfo?
>>>> To have constant-type dispatching without limitations you need the
>>>> static type information.
>>> What do you mean by this? At first I thought you meant that TypeInfo
>>> does not contain sufficient information to determine whether something
>>> is const or immutable, but that is not the case. If you wish to convert
>>> a Variant of a mutable thing to a const version of it, then you can
>>> check whether the type you get is convertible, and without any trouble
>>> -- the template instantiation to get the appropriate type will provide
>>> the TypeInfo you need.
>>>
>>> So what's the issue?
>> You may want to peruse the std.variant implementation. Variant is a
>> struct containing a buffer for the data and a pointer to function. The
>> function is a dispatcher for a handful of primitive operations.
>> The pointer to function is assigned from the address of a function
>> template. To get that address, you need the static type. That's the
>> necessity.
>> It's a very fast and very flexible design, but it does need the static
>> type during initialization.
>> Andrei
>
> Have you used std.variant at all lately? I think it's succumbed to bit rot as D2
> has evolved, because various strange things happen when I try to use it. If it's
> not on the agenda to be completely revamped for the new Phobos anyhow, I'll look
> into these errors in more detail and file some bug reports and patches.
I know std.variant is quintessential in a number of applications and
programming styles, but at the moment such are not my focus. Variants
have this interesting quirk that they are either vital or not needed at
all, indeed I remember people asking on this group "what is a variant
good for" etc.
It would be great if you submitted whatever failures you find in
std.variant.
Andrei
More information about the Digitalmars-d
mailing list