<type_traits>

class template
<type_traits>

std::add_cv

template <class T> struct add_cv;
Add const volatile qualification
Obtains the type T with both const and volatile qualification.

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

If T is not already const- and volatile-qualified, and is neither a reference nor a function (which cannot be cv-qualified), this is the same type as T but const and volatile qualified. 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 add cv-qualification to an object, const_cast can be used.

Template parameters

T
A type.

Member types

member typedefinition
typeIf T is not const- and volatile-qualified, and is neither a reference nor a function, the same type as T but cv-qualified.
Otherwise, T

Example

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

int main() {
  typedef std::add_cv<int>::type A;
  typedef std::add_cv<const int>::type B;
  typedef std::add_cv<volatile int>::type C;
  typedef std::add_cv<const volatile int>::type D;

  std::cout << std::boolalpha;
  std::cout << "typedefs of const volatile int:" << std::endl;
  std::cout << "A: " << std::is_same<const volatile int,A>::value << std::endl;
  std::cout << "B: " << std::is_same<const volatile int,B>::value << std::endl;
  std::cout << "C: " << std::is_same<const volatile int,C>::value << std::endl;
  std::cout << "D: " << std::is_same<const volatile int,D>::value << std::endl;

  return 0;
}

Output:
typedefs of const volatile int:
A: true
B: true
C: true
D: true


See also