Date: Wed, 15 Apr 2026 21:51:00 -0600
I find it very interesting that folk think the argument should be signed.
I have found that a very large percentage of ints should really be unsigned
as negative values are not permitted in normal usage.
As an example, I have used, and seen, this an uncountable number of times:
T array[10];
for (int i = 0; i < 10; ++i) { stuff }
I have been embracing unsigned ints more and more in an effort to make it
clear that negative values are not permitted.
On Wed, Apr 15, 2026, 21:07 Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> On Wednesday, 15 April 2026 18:31:41 Pacific Daylight Time Evan Teran via
> Std-
> Proposals wrote:
> > Today, users who want to avoid conversion warnings (which I personally
> > consider a best practice) must manually convert from signed to unsigned,
> > often after performing explicit negative checks which are easy to forget
> to
> > do. I would propose it as a template restricted to std::signed_integral
> so
> > the extra cost of the negative value check is only paid for signed types
> > and to avoid ambiguity with the existing size_type based implementation.
>
> The new overload won't help you if you need to check for negative values.
> If
> you made a calculation that could have become negative, you need to check
> it
> anyway because you've done something wrong and it shouldn't be on the
> called
> function to decide what to do. And what would it do: ignore doing nothing,
> or
> be the same as shrink_to_fit()?
>
> While I think (and many people agree) that all this API should have used
> signed integers in the first place, adding a few now is a can of worms I
> doubt
> LWG will want to open. Why not add to resize()? How about at() and
> operator[]?
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel Data Center - Platform & Sys. Eng.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
I have found that a very large percentage of ints should really be unsigned
as negative values are not permitted in normal usage.
As an example, I have used, and seen, this an uncountable number of times:
T array[10];
for (int i = 0; i < 10; ++i) { stuff }
I have been embracing unsigned ints more and more in an effort to make it
clear that negative values are not permitted.
On Wed, Apr 15, 2026, 21:07 Thiago Macieira via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> On Wednesday, 15 April 2026 18:31:41 Pacific Daylight Time Evan Teran via
> Std-
> Proposals wrote:
> > Today, users who want to avoid conversion warnings (which I personally
> > consider a best practice) must manually convert from signed to unsigned,
> > often after performing explicit negative checks which are easy to forget
> to
> > do. I would propose it as a template restricted to std::signed_integral
> so
> > the extra cost of the negative value check is only paid for signed types
> > and to avoid ambiguity with the existing size_type based implementation.
>
> The new overload won't help you if you need to check for negative values.
> If
> you made a calculation that could have become negative, you need to check
> it
> anyway because you've done something wrong and it shouldn't be on the
> called
> function to decide what to do. And what would it do: ignore doing nothing,
> or
> be the same as shrink_to_fit()?
>
> While I think (and many people agree) that all this API should have used
> signed integers in the first place, adding a few now is a can of worms I
> doubt
> LWG will want to open. Why not add to resize()? How about at() and
> operator[]?
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel Data Center - Platform & Sys. Eng.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
Received on 2026-04-16 03:51:15
