Any chance to call Tango as Extended Standard Library

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Jan 21 09:54:42 PST 2009


Lars Ivar Igesund wrote:
> Andrei Alexandrescu wrote:
> 
>> Lars Ivar Igesund wrote:
>>> Andrei Alexandrescu wrote:
>>>
>>>> Lars Ivar Igesund wrote:
>>>>> No, you misunderstand. I said safely call, not exceptionally
>>>>> efficient. To me a virtual call would be acceptable. However, at
>>>>> least in my cases, there would normally not be more than one
>>>>> imlemented interface and such it would be a tiny vtable.
>>>> Ok, so the scope is reducing nicely. We now have a few problems to
>>>> solve (some details glossed over for simplicity).
>>>>
>>>> a) Get from void* to the TypeInfo that's typing that void*. This
>>>> will involve a search as the void* could point really anywhere,
>>>> including untyped memory. So we have a core function:
>>>>
>>>> TypeInfo fromAddress(void * p);
>>>>
>>>> b) Starting from a TypeInfo, get an interface in case the
>>>> underlying struct implements that interface:
>>>>
>>>> Object TypeInfo.QueryInterface(TypeInfo someInterface);
>>>>
>>>> c) Finally, given a void* and an interface, invoke a method of that
>>>>  interface:
>>>>
>>>> T structCast!(Interface)(p).method(arguments);
>>> Since you used template lingo, it looks a bit like compile time
>>> functionality, but yes, very close now :)
>>>
>>> Also (I keep forgetting to mention important details) - I typically
>>> see this used in variadic functions, such that the typeinfo already
>>> is there.
>> But what are you ultimately trying to accomplish, and why do you must
>> lose all static information since it was just available to the caller?
>> Isn't there a simpler way to achieve your goal (e.g. using the new
>> variadics)? You are essentially asking for full-blown runtime scripting
>> for all structs.
> 
> Sorry; new variadics?

http://www.digitalmars.com/d/2.0/variadic-function-templates.html

Your use case suggests you are using the "look, ma, no templates" 
solution, whereas the new variadics are shown below that section.


Andrei



More information about the Digitalmars-d mailing list