C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Why wrapping into a struct for aligned_storage::type?
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2019-11-15 04:40:05


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. For example,
you can't pass an array by value into/out of a function.


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

Older Archives on Google Groups