c++typesqualifiers

Is 'const T*' a cv-unqualified type?


In C++ standard there is much wording including the term "cv-qualified" and "cv-unqualified". It's already known that a cv-qualified type is a type contains a set of cv-qualifiers: one of {"const"}, {"volatile"}, {"const, volatile"}, {" "}.

But I get confused when the type returned by std::remove_cv_t<const T*> is actually const T* not T*. Why?

Consider this declaration const int *volatile ptr{}, if we assume the type of ptr is cv T; what T is? what cv is?

Another examples,

const int&& r1 = 0; 
const int* &&r2 = 0;
const int *const &r3 = 0; 

Solution

  • But I get confused when the type returned by std::remove_cv_t<const T*> is actually const T* not T*. Why?

    const on the left is kind of a lie. If you use right hand const it makes a lot more sense. const T * can be rewritten as T const * and when read from right to left is "non-const pointer to a const T", so it is not cv-qualified. T * const on the other hand is const pointer to T, so it is cv-qualified.

    Consider this declaration const int *volatile ptr{}, if we assume the type of ptr is cv T; what T is? what cv is?

    With const int *volatile ptr you have a volatile pointer to a const int, so T is int const * and cv-qualification of T is volatile.

    In your last example, none of the references are cv-qualified as that would require const to be on the right hand side of the reference (i.e.: int & const). We are not actually allowed to do that though so reference are never cv-qualified.