I\'m writing C++ code in an environment in which I don\'t have access to the C++ standard library, specifically not to std::numeric_limits. Suppose I want to implem
std::numeric_limits
Use the bitwise NOT operator ~ on 0.
bitwise NOT
~
0
T allOnes = ~(T)0;
A static_cast(-1) assumes two's complement, which is not portable. If you are only concerned about unsigned types, hvd's answer is the way to go.
static_cast(-1)
Working example: https://ideone.com/iV28u0