Boost logo

Boost :

Subject: Re: [boost] Current Guidance on Compiler Warnings?
From: Gavin Lambert (boost_at_[hidden])
Date: 2018-11-26 22:11:30


On 27/11/2018 03:21, Alexander Grund wrote:
> I might agree with the size_t mistake: Using it for sizes may be ok, but
> as an index type might have been wrong.

As an index for a vector or array which cannot have a valid index below
zero, it's perfectly fine. And it's the only way you could index arrays
with INT_MAX < size <= SIZE_MAX.

The only case where it falls short is if you want to decrement below
zero, as in:

   for (size_t i = s.size() - 1; i >= 0; --i) { /* whoops */ }

(And a good compiler will warn you about this as well.)
This is readily solvable, however:

   for (size_t i = s.size(); i > 0; --i) { /* use i-1 */ }

(Or, of course, using iterators and ranges.)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk