C++ Logo

std-discussion

Advanced search

Re: Why wrapping into a struct for aligned_storage::type?

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Fri, 15 Nov 2019 13:40:05 +0300
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.

Received on 2019-11-15 04:42:28