C++ Logo


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 10:44:25 +0100
Am 09.11.19 um 09:52 schrieb Lyberta via Std-Discussion:
> Wilhelm Meier via Std-Discussion:
>> using size_type = std::condifition_t<(Size < 256), uint8_t,
>> std::conditional_t<(Size < 65536), uint16_t, ... >>>;
> If size_type is std::uint8_t then difference_type is std::int8_t and
> maximum size of such array is 127.

Oh yes, thanks.

> Of course, bigger problem is that CHAR_BIT can be more than 8.

I dont't see the point here. Can you elaborate on that?

> Generally, there are no fixed bit sizes that we can use in standard library.

I size_t is unsigned long long int, what then will be difference_type?

> Also, unsigned sizes just don't work given the rules of the language
> when it comes to arithmetic. We now have std::ssize to get signed sizes
> of containers and views.

in C++20?

Received on 2019-11-09 03:46:46