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 19:52:29 +0000
I wouldn't suggest introducing #if defined() in to production code for this purpose. It's definitely not modern C++ programming.

An #ifdef solution would work but it's a bit messy. Also I believe I mentioned not mentioning concrete types.

Type erasure techniques would not add simplicity to existing code or provide a reasonable solution.

Your suggested solution is very old software development.

--James S.

On Friday, November 10th, 2023 at 6:39 AM, Nikl Kelbon via Std-Proposals <std-proposals_at_[hidden]> wrote:

> Firstly:
> [image.png]
> for such kind of using C++
>
> Second,
>
> #ifdef TESTS_ENABLED
> #define maybe_final final
> #else
> #define maybe_final
> #endif
>
> struct Abc maybe_final {
>
> };
>
> And, of course, you can use type erasure instead of virtual inheritance
>
> пт, 10 нояб. 2023 г. в 05:22, Smith, Jim via Std-Proposals <std-proposals_at_[hidden]>:
>
>> 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

Received on 2023-11-25 19:52:44