C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Optimize away VTBL when using single inheritance

From: Smith, Jim <jim.smith_at_[hidden]>
Date: Sat, 25 Nov 2023 18:34:41 +0000
That's pretty much what I'm thinking could be accomplished at compile-time. In the GoogleTests code for example the base may only consist of pure virtual functions for the interface.

In the C++ standard there are templates for compile-time conditions, i.e., std::is_same in <type_traits>so my first thought is that using the same template based approach could work in this scenario.

-James S.

On Thursday, November 9th, 2023 at 8:50 PM, Sebastian Wittmeier via Std-Proposals <std-proposals_at_[hidden]> wrote:

> So the VTBL would still exist, but for some order od operations (here: Create + someVirtualFunc()) the indirection could/would be optimized out? As the class behind the interface is known from the Create function in this case?
>
>> -----Ursprüngliche Nachricht-----
>> Von: Breno Guimarães via Std-Proposals <std-proposals_at_[hidden]>
>> Gesendet: Fr 10.11.2023 02:37
>> Betreff: Re: [std-proposals] Optimize away VTBL when using single inheritance
>> An: Std-Proposals <std-proposals_at_[hidden].org>;
>> CC: Breno Guimarães <brenorg_at_[hidden]>;
>>
>> Hi,
>>
>> Perhaps this should be directed a compiler vendor then?
>>
>> Best Regards,
>> Breno G
>>
>> Em qui., 9 de nov. de 2023 22:22, Smith, Jim via Std-Proposals <std-proposals_at_[hidden]> escreveu:
>>
>>> Hi All,
>>>
>>> Test-driven development (TDD) is my de facto standard for writing software. On some projects I can't use TDD because interfaces introduce VTBL operation into the code. For me this is a serious issue.
>>>
>>> I've always used C++ interfaces i.e., classes with all pure virtual functions for TDD, especially when implementing a design patterns like Factory.
>>>
>>> I'm proposing a compiler option that will turn a virtual call through an interface, to a direct call on the object. For example,
>>>
>>> interface* i = Factory::Create();
>>>
>>> i->someVirtualFunc();
>>>
>>> In cases where single inheritance is used i->someVirtualFunc() would be optimized to a direct call on the object without any VTBL operation.
>>>
>>> This way the TDD code can use the standard VTBL operations, and in production builds a flag can be set to optimize it away. I can't do this myself without mentioning the concrete type created by the factory but the compiler can make the optimization.
>>>
>>> --James S.
>>>
>>> --
>>> Std-Proposals mailing list
>>> Std-Proposals_at_[hidden]
>>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>>
>> --
>> Std-Proposals mailing list
>> Std-Proposals_at_lists.isocpp.org
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-11-25 18:35:03