Date: Thu, 17 Aug 2023 14:41:32 +0300
On Thu, 17 Aug 2023 at 14:25, Timur Doumler <cpp_at_[hidden]> wrote:
> AFAIK it does however does *not* provide a guarantee that there is an actual array, that is, a T[N], under the hood anywhere. A hostile implementation could implement std::array<T, 2> for example as a struct { T first, second; };
>
>
> No, it can't. That implementation wouldn't fulfill the requirements of
> array::data(), which are that
> [data(), data() + size())
> is a valid range (and that range is denoted by pointer arithmetic, and
> traversed by pointer arithmetic,
> because data() and data()+size() are just pointers).
>
>
> The implementation can fulfil this requirement by fiat – because the compiler makes it so.
The pointer arithmetic is defined only for an array.
>std::complex has this property, too – although it's specified differently (see [complex.numbers.general]/4), the effect is the same, you can use pointer arithmetic here, because the Standard says that you can.
To do that, the standard would need to say something additional, like
it does for std::complex, but since it doesn't, an array is there.
>None of this guarantees that there is an actual T[N] anywhere under the hood, certainly not for std::array as far as I can see.
Well, yeah - the actual problem is that nothing prevents the
implementation from putting a T[N+IMPL_DEFINED_CONSTANT] there.
> AFAIK it does however does *not* provide a guarantee that there is an actual array, that is, a T[N], under the hood anywhere. A hostile implementation could implement std::array<T, 2> for example as a struct { T first, second; };
>
>
> No, it can't. That implementation wouldn't fulfill the requirements of
> array::data(), which are that
> [data(), data() + size())
> is a valid range (and that range is denoted by pointer arithmetic, and
> traversed by pointer arithmetic,
> because data() and data()+size() are just pointers).
>
>
> The implementation can fulfil this requirement by fiat – because the compiler makes it so.
The pointer arithmetic is defined only for an array.
>std::complex has this property, too – although it's specified differently (see [complex.numbers.general]/4), the effect is the same, you can use pointer arithmetic here, because the Standard says that you can.
To do that, the standard would need to say something additional, like
it does for std::complex, but since it doesn't, an array is there.
>None of this guarantees that there is an actual T[N] anywhere under the hood, certainly not for std::array as far as I can see.
Well, yeah - the actual problem is that nothing prevents the
implementation from putting a T[N+IMPL_DEFINED_CONSTANT] there.
Received on 2023-08-17 11:41:45