C++ Logo

std-proposals

Advanced search

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

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Wed, 2 Sep 2020 18:47:14 -0400
On Wed, Sep 2, 2020 at 6:30 PM Steve Hearnden <steve_at_[hidden]> wrote:

> My proposal was intended to allow Arthur’s sample to be written as below.
>
>
>
> template<class T, size_t Cap>
>
> class fixed_capacity_vector {
>
> [[unconstructed]] T data_[ Cap];
>
>
So it saves you exactly zero lines of code. What's the point? (Trick
question: There is no point. You don't need this feature.)


> T* data() { return data_; } // no cast necessary
>
> const T* data() const { return const_cast<const T*>(data_); } //
> better cast - just a const_cast
>

FYI, you don't need the const_cast either; the data members of a `const
fixed_capacity_vector` are themselves const already.

–Arthur

Received on 2020-09-02 17:50:54