If I need a type that satisfy std::is_unsigned
and std::is_integral
, do I have to check both or only std::is_unsigned
?
cppreference has this line for is_unsigned
(https://en.cppreference.com/w/cpp/types/is_unsigned):
this results in true for the unsigned integer types and the type bool and in false for the signed integer types and the floating-point types. For any other type, value is false.
so if is_unsigned
is true
, then is_integral
will as well.
Yes, it does according to cppreference.
Just keep in mind that this doesn't work everywhere, and is only guaranteed for native types. I had an issue with boost::multiprecision
giving wrong results for integers. The best way to do this is with numeric_limits
:
std::numeric_limits<MyIntType>::is_signed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With