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;
r1
is cv1 T1
; what T1
is? what cv1
is?r2
is cv2 T2
; what T2
is? what cv2
is?r3
is cv3 T3
; what T3
is? what cv3
is?But I get confused when the type returned by
std::remove_cv_t<const T*>
is actuallyconst T*
notT*
. 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 ofptr
iscv T
; whatT
is? whatcv
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.