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;
- If the type of
r1iscv1 T1; whatT1is? whatcv1is? - If the type of
r2iscv2 T2; whatT2is? whatcv2is? - If the type of
r3iscv3 T3; whatT3is? whatcv3is?
conston the left is kind of a lie. If you use right hand const it makes a lot more sense.const T *can be rewritten asT const *and when read from right to left is "non-const pointer to aconst T", so it is not cv-qualified.T * conston the other hand isconstpointer toT, so it is cv-qualified.With
const int *volatile ptryou have avolatilepointer to aconst int, soTisint const *and cv-qualification ofTisvolatile.In your last example, none of the references are cv-qualified as that would require
constto 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.