char const*
is a pointer to a const char
, but the pointer itself is not const
. To remove the constness from the type being pointed to, you could do this:
std::add_pointer<typename std::remove_const<typename std::remove_pointer<T>::type>::type>::type
Or alternatively:
typename std::remove_const<typename std::remove_pointer<T>::type>::type*
We remove the pointer from const char*
to get const char
, then remove const to get char
, then add the pointer back to get char*
. Not particularly pretty. To test:
typedef const char * type_before;
std::cout << typeid(type_before).name() << std::endl;
typedef typename std::remove_const<typename std::remove_pointer<type_before>::type>::type* type_after;
std::cout << typeid(type_after).name() << std::endl;
With g++ on my system, this outputs:
PKc
Pc
This should give you a hint about what "PKc" means. P for pointer, c for char
, and K for konst
;)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…