Hi,
Something I forgot to add earlier, the reason why the loop continues:
In the expression
Xdata.size()-B
B
is promoted from
int
to
std::size_t
If the expression is equal to zero, then the condition is true. In the comparison between
i
and the expression,
i
is also implicitly promoted to
std::size_t
. When
i
is decremented it would have a value of say 2
^{64} - 1 (if
std::size_t
is really a
unsigned long long
*), because
std::size_t
can't have negative values, so the loop continues.
* The type of
std::size_t
is often set to the largest unsigned type the system has, but this is not guaranteed by the standard.
So this is why it is problematic to mix signed and unsigned types when doing arithmetic.
Also there should have been a compiler warning about this, if one has the warnings turned on. Always have compiler warnings turned on to the highest level one can get away with. It's worth reading the manual to turn on specific warnings. With g++ and clang++ there quite a few warnings
not turned on by
-Wall -Wextra -pedantic
GeorgeP wrote: |
---|
C++20 introduced the reverse range adaptor. |
Ah cool, thanks George. There is so much stuff in the ranges library, awesome.