class template
<type_traits>

std::add_volatile

template <class T> struct add_volatile;
Add volatile qualification
Obtains the type T with volatile qualification.

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

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

Template parameters

T
A type.

Member types

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

Example

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

int main() {
  typedef std::add_volatile<int>::type A;            // volatile int
  typedef std::add_volatile<volatile int>::type B;   // volatile int     (unchanged)
  typedef std::add_volatile<int* volatile>::type C;  // int* volatile    (unchanged)
  typedef std::add_volatile<volatile int*>::type D;  // volatile int* volatile
  typedef std::add_volatile<volatile int&>::type E;  // volatile int&    (unchanged)

  std::cout << std::boolalpha;
  std::cout << "checking volatileness:" << std::endl;
  std::cout << "A: " << std::is_volatile<A>::value << std::endl;
  std::cout << "B: " << std::is_volatile<B>::value << std::endl;
  std::cout << "C: " << std::is_volatile<C>::value << std::endl;
  std::cout << "D: " << std::is_volatile<D>::value << std::endl;
  std::cout << "E: " << std::is_volatile<E>::value << std::endl;

  return 0;
}


Output:
checking volatileness:
A: true
B: true
C: true
D: true
E: false

See also

<type_traits>