I have encountered a problem while I was using a loop like this,
//vector<int> sides;
for (int i = 0; i < sides.size()-2; i++) {
if (sides[i] < sides[i+1] + sides[i+2]) {
...
}
}
The problem was that the size() method uses an unsigned number. So, vectors of size less than 2 make an undefined outcome.
I understand that I should have used an unsigned variable for the loop but it doesn't solve the problem. So I had to deal with it by typecasting or using some conditions.
My question is that why do STL uses an unsigned int to eliminate negative index access violation and generating more problems?