Home:ALL Converter>How to deduce a type by remove_cv function (const volatile int* vs const volatile int vs int * const volatile)

How to deduce a type by remove_cv function (const volatile int* vs const volatile int vs int * const volatile)

Ask Time:2015-03-20T15:02:08         Author:Vladimir Kadirko

Json Formatter

There is a function "remove_cv" (http://en.cppreference.com/w/cpp/types/remove_cv) to remove constant and volatile.

My question is why it is possible to remove from "const volatile int" to "int" and from "int * const volatile" to "int*" but "const volatile int*" is the same as before remove.

The possible code is from the site
template< class T >
struct remove_cv {
    typedef typename std::remove_volatile<typename std::remove_const<T>::type>::type type;
};

template< class T > struct remove_const          { typedef T type; };
template< class T > struct remove_const<const T> { typedef T type; };


template< class T > struct remove_volatile             { typedef T type; };
template< class T > struct remove_volatile<volatile T> { typedef T type; };

I can't understand the rules for the pointer type deduction. Can you guys show me the way for/how compiler possibly do it? Are there rules for the deduction?

Author:Vladimir Kadirko,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/29161143/how-to-deduce-a-type-by-remove-cv-function-const-volatile-int-vs-const-volatil
yy