bool is_sentinel() const
{
return milliseconds==~uintmax_t(0);
}
I have found this line of code in thread_data.hpp, I am wondering why is it ~uintmax_t(0) instead of -1 ?
EDIT:
if reason is to avoid compiler warnings, why don’t use :
std::numeric_limits(decltype(milliseconds)>::max()
?
One reason for using uintmax_t in the first place is that we don’t know what the largest type is. Is it
unsigned longorunsigned long long?My guess is that using
~uintmax_t(0)to produce a large unsigned value simply produces the least number of warnings on the largest number of compilers.It is common for compilers to warn if you mix signed and unsigned values, or that using a minus on an unsigned value (
-1ull) surprisingly(?) gives an unsigned result.