26 Nov
2018
26 Nov
'18
10:11 p.m.
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.)