Can I determine whether a pointer is of integral type via type traits?
-
26-10-2019 - |
Question
By using type traits, I can find out whether a type is integral or a pointer (and more). Is it also possible to find out whether the pointer being passed is that of an integral data type (int, float, char) and not an object?
EDIT: In addition to Armen's answer, if anybody is using the LOKI library instead of Boost, the functionality of remove pointer
is similar to TypeTraits::PointeeType
Solution
boost::is_pointer<T>::value &&
boost::is_integral<boost::remove_pointer<T>::type>::value
Btw float
is not integral. You probably need is_arithmetic
OTHER TIPS
template <typename T>
struct IsPointerToInt {
static const bool value = false;
};
template <>
struct IsPointerToInt<int *> {
static const bool value = true;
};
// ... other specializations for the types you are interested in ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow