Consider the following tests:
std::is_same<T, bool>::value
std::is_same<T, char>::value
std::is_same<T, short int>::value
std::is_same<T, int>::value
std::is_same<T, long int>::value
std::is_same<T, long long int>::value
std::is_same<T, float>::value
std::is_same<T, double>::value
std::is_same<T, long double>::value
The problem is if T = const unsigned char, all tests will be false, and I would like this one std::is_same<T, char>::value to be true. Or if T = volatile signed long long int I would like std::is_same<T, long long int>::value to be true. How to do that with type_traits ?
Use std::remove_cv to remove const and volatile if present:
std::is_same<std::remove_cv<T>::type, long long int>::value;
You can use std::remove_cv to take care of the const-volatile specifiers.
And you can use std::make_signed to take care of the signed/unsigned issue. Although, I don't particularly like that idea (is unsigned char really the same as char? No.).
std::is_same< std::make_signed< std::remove_cv<T> >, char >::value;
Will be true for any of char, unsigned char, const char, const unsigned char, and the volatile versions of those.
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