Date: Tue, 28 Apr 2020 18:42:17 +0200
On 2020-04-28 at 15:47, Gennaro Prota via Std-Discussion wrote:
> On Tue, Apr 28, 2020 at 3:36 PM Bo Persson via Std-Discussion
> <std-discussion_at_[hidden]> wrote:
>>
>> On 2020-04-28 at 15:18, Gennaro Prota via Std-Discussion wrote:
>>> On Tue, Apr 28, 2020 at 1:43 PM Bo Persson via Std-Discussion
>>> <std-discussion_at_[hidden]> wrote:
>>>>
>>>> On 2020-04-28 at 12:46, Gennaro Prota via Std-Discussion wrote:
>>>>> Hi All,
>>>>>
>>>>> what is the reason why the non-array version of std::ssize() returns
>>>>>
>>>>> std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(c.size())>>
>>>>>
>>>>> rather than just
>>>>>
>>>>> std::ptrdiff_t
>>>>>
>>>>> ?
>>>>>
>>>>> Thanks a lot.
>>>>>
>>>>
>>>> The containers size_type is not required to be convertible to ptrdiff_t.
>>>> This will try to find some other type in that case.
>>>
>>> Isn't a container's size_type guaranteed to be an unsigned integer type?
>>>
>>
>> Maybe, but *what* integer type?
>
> I think any integer type is convertible to ptrdiff_t.
>
Unless it is a wider type. It could be that ptrdiff_t is int and some
container's size() function returns unsigned long long. It just *could*.
Bo Persson
> On Tue, Apr 28, 2020 at 3:36 PM Bo Persson via Std-Discussion
> <std-discussion_at_[hidden]> wrote:
>>
>> On 2020-04-28 at 15:18, Gennaro Prota via Std-Discussion wrote:
>>> On Tue, Apr 28, 2020 at 1:43 PM Bo Persson via Std-Discussion
>>> <std-discussion_at_[hidden]> wrote:
>>>>
>>>> On 2020-04-28 at 12:46, Gennaro Prota via Std-Discussion wrote:
>>>>> Hi All,
>>>>>
>>>>> what is the reason why the non-array version of std::ssize() returns
>>>>>
>>>>> std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(c.size())>>
>>>>>
>>>>> rather than just
>>>>>
>>>>> std::ptrdiff_t
>>>>>
>>>>> ?
>>>>>
>>>>> Thanks a lot.
>>>>>
>>>>
>>>> The containers size_type is not required to be convertible to ptrdiff_t.
>>>> This will try to find some other type in that case.
>>>
>>> Isn't a container's size_type guaranteed to be an unsigned integer type?
>>>
>>
>> Maybe, but *what* integer type?
>
> I think any integer type is convertible to ptrdiff_t.
>
Unless it is a wider type. It could be that ptrdiff_t is int and some
container's size() function returns unsigned long long. It just *could*.
Bo Persson
Received on 2020-04-28 11:45:24