class template
<type_traits>

std::remove_cv

template <class T> struct remove_cv;
Remove cv qualification
Obtains the type T without any top-level const or volatile qualification.

The transformed type is aliased as member type remove_cv::type.

If T is cv-qualified (either const and/or volatile), this is the same type as T but with its cv-qualification removed. Otherwise, it is T unchanged.

Notice that this class merely obtains a type using another type as model, but it does not transform values or objects between those types. To explicitly remove the cv-qualifier of an object, const_cast can be used.

Template parameters

T
A type.

Member types

member typedefinition
typeIf T is cv-qualified, the same type as T but with any cv-qualification removed.
Otherwise, T

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// remove_cv example
#include <iostream>
#include <type_traits>

int main() {
  typedef const volatile char cvchar;
  std::remove_cv<cvchar>::type a;       // char a
  std::remove_cv<char* const>::type b;  // char* b
  std::remove_cv<const char*>::type c;  // const char* c (no changes)

  if (std::is_const<decltype(a)>::value)
    std::cout << "type of a is const" << std::endl;
  else
    std::cout << "type of a is not const" << std::endl;

  if (std::is_volatile<decltype(a)>::value)
    std::cout << "type of a is volatile" << std::endl;
  else
    std::cout << "type of a is not volatile" << std::endl;

  return 0;
}


Output:
type of a is not const
type of a is not volatile

See also

<type_traits>