c++c++11type-traitsqualifiers

Type traits which are true for all const/volatile/signed/unsigned version of a fundamental type


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 ?


Solution

  • Use std::remove_cv to remove const and volatile if present:

    std::is_same<std::remove_cv<T>::type, long long int>::value;