Any chance to call Tango as Extended Standard Library
Lars Ivar Igesund
larsivar at igesund.net
Tue Jan 20 09:58:24 PST 2009
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.
And an additional question only semi-related to the above; is it possible to have a function that works as a variadic function, but where the number of arguments is restricted to 1 (or 2 or 3 but not unbounded).
Oh oh, I'm getting into a steam (and even less related ...) - variadic ref parameters.
--
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango
More information about the Digitalmars-d
mailing list