C++ Logo


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 22:42:58 +0300
On Wed, 2 Sep 2020 at 22:35, Steve Hearnden via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> Thanks for your replies. I think that std::optional is similar to what I was thinking about, but was requesting an extension to C++ to produce different behaviour.
> The implementation of std::optional with my Microsoft compiler has a union which is something like....
> union {
> char _Dummy;
> T _Value;
> };
> This is an excellent example of my use-case. The code in the library has to side-step the behaviour of the compiler of constructing items, and would be replaced by my proposal with ....
> [[unconstructed]] _Value;
> We would simplify implementations of std::optional, focusing on the behaviour we require, rather than hiding from the compiler the use cases.

Well, anecdotally, at least one maintainer of std::optional doesn't
need another way to spell "union". The same maintainer
calls into dispute the suggestion that this facility simplifies the
implementation of std::optional, because the pre-c++23 versions
of it would need to use a union anyway.

Having a core language attribute with semantic effects seems like a
very poor way to support something as uncommon
as this, especially when it's just another way to spell
already-existing ways to implement the same thing.

Received on 2020-09-02 14:46:38