C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: Why is size_type in std::array an alias for size_t?
From: Wilhelm Meier (wilhelm.meier_at_[hidden])
Date: 2019-11-09 01:45:03


Am 09.11.19 um 08:27 schrieb Peter C++:
> If you know that your size_type values always fit into an uint_8t you can store it there if needed, eg, to iterate. Std::array never keeps its size somewhere at run time, so I fail to see the issue.

I don't want to store the actual size inside the array. I just want der
size_type declaration to be adaptive:

using size_type = std::condifition_t<(Size < 256), uint8_t,
std::conditional_t<(Size < 65536), uint16_t, ... >>>;

So a user of std::array can use the smallest unsigned int wenn using
size_type.

>
> sent from a mobile device so please excuse strange words due to autocorrection.
> Prof. Peter Sommerlad
> peter.Sommerlad_at_[hidden]
> +41-79-432 23 32
>
>> On 9 Nov 2019, at 07:24, Wilhelm Meier via Std-Discussion <std-discussion_at_[hidden]> wrote:
>>
>> 
>>
>>> 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.
>>
>>
>> --
>> Std-Discussion mailing list
>> Std-Discussion_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups