C++ Logo


Advanced search

Re: C++ create a class with array members which arenot constructed.

From: Steve Hearnden <steve_at_[hidden]>
Date: Wed, 2 Sep 2020 22:52:41 +0100
I didn’t think this was stackoverflow, and I didn’t expect an implementation from a carefully crafted question.

I thought the std-proposals, was for a discussion of language proposals. I don’t dispute that it is possible to get arbitrary memory either from the heap, or embedded in unionized memory inside an object, on the stack, or on the heap. I am suggesting that the syntax used to achieve that in the current language (all suggested), are somewhat clumsy, and create code which obscures its purpose with a necessary indirection to convert from the unconstructed form to the constructed form.

Reviewing existing containers left me considering the code is less clear and more complicated than it needs to be due to the requirement to ensure that the compiler doesn’t see the reserved space as the type (or an array of the type), to ensure the compiler doesn’t construct / destruct the item(s).

This proposal is to provide a syntax where the intent of the space / memory is more clear, and the developer can then focus on implementing their requirements, rather than hiding their intent from the compiler.

Using an attribute, would keep it away from being commonly used, or easy to stumble across (unlike the union)

Sent from Mail for Windows 10

From: Ville Voutilainen
Sent: 02 September 2020 22:17
To: sotrdg sotrdg via Std-Proposals
Cc: Steve Hearnden; Arthur O'Dwyer
Subject: Re: [std-proposals] C++ create a class with array members which arenot constructed.

On Thu, 3 Sep 2020 at 00:11, Arthur O'Dwyer via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> I'm amazed that nobody has just given you teh codez yet.

I'm likewise amazed that someone expects me to write a small-vector
for someone who asks whether
an attribute that delays initialization of an object is a good
addition to C++. I boldly presumed that
the question/suggestion was more general than just about how to get
one's hands into a small-vector.

Received on 2020-09-02 16:57:03