C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Array Index in Range-based For Loops

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Thu, 2 Mar 2023 09:34:48 +0000
On Thu, 2 Mar 2023, 01:04 Edward Catmur wrote:

>
>
> On Wed, 1 Mar 2023 at 18:54, Jonathan Wakely via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
>
>>
>>
>> On Wed, 1 Mar 2023, 20:48 Ray Gardener via Std-Proposals, <
>> std-proposals_at_[hidden]> wrote:
>>
>>> Not gonna lie, if I see code exploiting integer overflow, I reject it.
>>> It just smells hoity-toity. I like code to be dead obvious.
>>>
>>> And as for assigning negative numbers to unsigned types, whatever
>>> happened to type safety?
>>>
>>
>> Would you prefer -1zu then? That's a literal of type size_t so there's no
>> negative number and no question of it being not "type safe". It means
>> exactly the same thing though.
>>
>
> Strictly speaking, it's a unary expression where the cast-expression is a
> literal of type size_t.
>

Ah yes, thanks. The literal is 1zu.

I'm not entirely sure that size_t can't promote to int, although obviously
> it doesn't on any sensible platform.
>

H8/300 with the -mint32 option has 16-bit size_t and 32-bit int and it's a
pain in the backside.

This is a narrowing conversion:
string_view s2{s.data(), s.size()+0zu};

Received on 2023-03-02 09:35:04