Any chance to call Tango as Extended Standard Library

Lars Ivar Igesund larsivar at igesund.net
Sun Jan 18 13:16:23 PST 2009


Andrei Alexandrescu wrote:

> Lars Ivar Igesund wrote:
>> Andrei Alexandrescu wrote:
>> 
>>> Lars Ivar Igesund wrote:
>>>> Jason House wrote:
>>>> 
>>>>> Andrei Alexandrescu wrote:
>>>>> 
>>>>>> I'd be curious to find out more about a runtime queryable
>>>>>> struct interface. How would it work? What idioms would it
>>>>>> enable?
>>>>> I don't know what Lars is thinking of, but I think of struct
>>>>> interfaces as a non-polymorphic / compile-time inheritance.
>>>>> AKA, you can have a struct implement it, but you can't cast it
>>>>> to a base struct/interface.  Outside of defining the struct,
>>>>> I'd expect it to only be usable in templates and is-expressions
>>>>> 
>>>> Nope, I want something that works at runtime. Inheritance
>>>> could/should be non-polymorphic and compile-time, but I want to
>>>> know at runtime that a void* has implemented a given interface.
>>> Consider you can avail yourself of a function:
>>> 
>>> bool implements(Interface)(void* p);
>>> 
>>> What would you do with it?
>> 
>> Assuming that I (after getting a positive result from a call to the
>> above, and that I have an interface with the member foo) can then
>> safely call p.foo, I could do a lot of stuff that I can't do today.
> 
> I understand. So essentially you don't want to see whether a void*
> implements an interface, but instead you want to get that interface,
> i.e. obtain the pointers to the functions in the interface as
> implemented by whatever struct that void* stands for. In doing so you
> also claim that all of that is entirely possible to do so at low or no
> cost. After the functions in that interface are obtained, you also
> implicitly claim that they won't hurt performance of the design by using
> indirect calls.
> 
> If my understanding of the above is correct, this is an extraordinary
> claim. It is, in fact, so extraordinary that I'll bite the bullet and
> claim myself that you are thoroughly confused about what you want and to
> what extent it is realizable. My guess is that if you follow your idea
> to its ultimate conclusion, you will be inexorably drawn to
> rediscovering how vtables work and what tradeoffs they embed when
> compared to direct function calls.

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.

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango



More information about the Digitalmars-d mailing list