On Friday, 28 August 2015 at 06:19:55 UTC, Jacob Carlborg wrote:
On 2015-08-26 20:59, Adam D. Ruppe wrote:

Yes, exactly. COM and C++ things won't necessarily have a D TypeInfo
available and since interfaces can be them, it can't be sure.

What I do there is to just cast the interface to Object. Then you should check for null to cover those cases, then you can typeid or classinfo it.

Is it possible to detect at compile time if an interface is not a native D interface?

Now when I think about it, we actually have four (!) different kinds of interfaces. Native D, C++, Objective-C and COM.

I don't know about Objective-C, but:

- for native D interfaces __traits(getVirtualIndex, NativeInterface.firstFunction) == 1 since the first entry in vtbl is the contained object - for C++ interfaces __traits(getVirtualIndex, CPPInterface.firstFunction) == 0 - COM interfaces: __traits(getVirtualIndex, CPPInterface.firstFunction) == 0 and inherit IUnknown

At runtime, it's simple, you have the m_flags member of TypeInfo_Class (isCPPclass, isCOMclass)

Reply via email to