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 12:41:58 +0100
Am 09.11.19 um 11:30 schrieb Lyberta via Std-Discussion:
> Wilhelm Meier via Std-Discussion:
>>> 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?
> That means that generally reasoning about sizes of types is difficult.
> What if CHAR_BIT is 10?
> Then both Size < 256 and Size < 65536 don't make sense as now all the
> numbers derived from number of bits in a byte are different.

Yes of course. But my proposal was to use uint8_t oder uin16_t, so the
CHAR_BIT doen't matter here.

In reality one would surely use std::numeric_limits<>::max() instead of
the heard-coded numbers.

>> I size_t is unsigned long long int, what then will be difference_type?
> std::size_t is tied to std::ptrdiff_t. So if std::size_t is unsigned
> long long int then std::ptrdiff_t is long long int.

Ok, that ist the same issue as with uint8_t and int8_t,

>>> 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.

Received on 2019-11-09 05:44:20