C++ Logo

std-discussion

Advanced search

Re: Why is size_type in std::array an alias for size_t?

From: Wilhelm Meier <wilhelm.meier_at_[hidden]>
Date: Sat, 9 Nov 2019 08:23:59 +0100
Am 09.11.19 um 01:58 schrieb Thiago Macieira via Std-Discussion:
> On Thursday, 7 November 2019 22:46:22 PST Wilhelm Meier via Std-Discussion
> wrote:
>> I wonder, if this is intentional, since std::array could declare the
>> size_type depending on the actual size of the array, e.g. an
>> implementation could declare size_type an alias to uint8_t if the size
>> of the array is less than 256 or uint16_t if the size of the array is
>> less than 65536.
>
> No, this is intentional. The std::array::size_type should be the type that
> sizeof(actual_array) returns. That's size_t.
>

Well, on one side this is understandable, but on the other side an
implementation für small µC could get some benefit from declaring
size_type to the small unsigned integer possible for the actual size of
the array. And I don't see any obstackles doing so.

Received on 2019-11-09 01:26:20