C++ Logo


Advanced search

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

From: Lyberta <lyberta_at_[hidden]>
Date: Sat, 09 Nov 2019 08:52:00 +0000
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.

Of course, bigger problem is that CHAR_BIT can be more than 8.
Generally, there are no fixed bit sizes that we can use in standard library.

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 02:54:55