Usually, if I need to determine if there is a const type, I just use boost::is_const . However, I ran into difficulties when trying to detect the constness of a nested type. Consider the following pattern template, which is specialized for const types:
template <class T> struct traits { typedef T& reference; }; template <class T> struct traits<const T> { typedef T const& reference; };
The problem is that boost::is_const does not detect that traits<const T>::reference is of type const .
For example:
std::cout << std::boolalpha; std::cout << boost::is_const<traits<int>::reference>::value << " "; std::cout << boost::is_const<traits<const int>::reference>::value << std::endl;
Output: false false
Why doesn't it print false true ?
Channel72
source share