Well, an extended definition of shift operators may change the direction
in this case. Of, course the standard C++ operators do not.
Yes. Especially because of that. Otherwise some inexperienced
maintainer might imagine it as extended.
However, there are many situations where a value must be a natural
number. Think about the length of a string or the number of elements in
an array or container or any other countable object.
One advantage of using unsigned integers in this cases is that you
usually need only one comparison to verify the validity of a value. E.g.:
unsigned index;
std::string str;
...
if (index>= str.length())
// Error
...
If you use singed int you have to check against zero too in general, to
avoid undefined behavior.
That is the only significant advantage of using unsigned there but
that has been discussed to death. Lot of people for some reason prefer
-1 instead of 4294967295 there ... and since both are wrong values i
am indifferent. I am sure that reverse cycles using unsigned that way
may confuse the crap out of beginners however:
std::string str("Noob trap");
for ( unsigned i = str.size()-1; i< str.size(); --i )
{
str
+= 13;
}
Of course, there are platforms where unsigned integers are slow, because
they are not supported by the hardware natively.