C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Why wrapping into a struct for aligned_storage::type?
From: Gennaro Prota (gennaro.prota_at_[hidden])
Date: 2019-11-18 02:09:38


On Fri, Nov 15, 2019 at 11:40 AM Andrey Semashev via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> On 2019-11-15 13:32, Gennaro Prota via Std-Discussion wrote:
> > Hi,
> >
> > from n3337 (first draft after C++11):
> >
> > [Note: A typical implementation would define aligned_storage as:
> >
> > template <std::size_t Len, std::size_t Alignment>
> > struct aligned_storage {
> > typedef struct {
> > alignas(Alignment) unsigned char __data[Len];
> > } type;
> > };
> >
> > I wonder: why the additional struct around the array?
>
> It makes the type have value semantics, instead of array.

That's indeed a consequence. I don't know if it is the reason this is
done, though (but if you know for sure, I trust you).

> For example,
> you can't pass an array by value into/out of a function.

Yeah. Although, off-hand, I can't imagine a case where I'd use
std::aligned_storage::type as parameter type or return type.

--
--
.:: Gennaro Prota ::.
.:: https://about.me/gennaro.prota ::.

STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups