C++ Logo

std-proposals

Advanced search

Re: C++ create a class with array members which are notconstructed.

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Wed, 2 Sep 2020 23:54:48 +0300
On Wed, 2 Sep 2020 at 23:20, Nikolay Mihaylov via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> To be honest, std::optional is not the most performant code, see following for std::varian, which is similar.
>
> https://stackoverflow.com/questions/62404209/why-does-clang-handle-exceptions-for-this-trivial-stdvariant-code
>
> but you can always use a char / byte array and use placement new - will be more difficult to code, but in this way you will be able to know "what happens" all the time.

variant has much more somewhat problematic gunk in its implementation
for an optimizer to do a good job at it
than optional does. gcc still doesn't like the
arrays-of-function-pointers inside variant, but I wouldn't expect
the use of optional to result in bad codegen. And even if it did, such
problems are likely to be solved before
we get to have an attribute that basically just tells a compiler to
generate a union.

Received on 2020-09-02 15:58:28