I am learning C++ by reading Stroustrup\'s \"Principles and Practice Using C++\".
In the section about pre- and post-conditions there is the following example of functio
Since C++11 there is a boolean value you can test:
std::numeric_limits::is_modulo
If this value is true
then signed arithmetic behaves in a wraparound fashion, and there is no undefined behaviour in the original code. A negative value could indeed be produced and so the test in the original code is meaningful.
For further discussion of is_modulo
see here