Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

std::add_volatile in C++ with Examples

  • Last Updated : 12 Jun, 2020

The std::add_volatile template of C++ STL is present in the <type_traits> header file. The std::add_volatile template of C++ STL is used to get the type T with volatile qualification. The function std::is_volatile is used to check if type T is volatile qualified or not.

Header File:


Template Class:

template < class T >
struct add_volatile;



Parameter: The template std::add_volatile accepts a single parameter T(Trait class) which is used to get the type T with volatile qualification.

Below is the program to demonstrate std::add_volatile: in C++:


// C++ program to illustrate
// std::add_volatile
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
// Driver Code
int main()
    // Declare variable of type
    // volatile (int, const int, const int*,
    // int * const and const int&)
    typedef add_volatile<int>::type A;
    typedef add_volatile<volatile int>::type B;
    typedef add_volatile<int* volatile>::type C;
    typedef add_volatile<volatile int*>::type D;
    typedef add_volatile<volatile int&>::type E;
    cout << boolalpha;
    // Checking the volatileness of
    // the above declared variable
    cout << "checking volatileness:"
         << endl;
    cout << "A: "
         << is_volatile<A>::value
         << endl;
    cout << "B: "
         << is_volatile<B>::value
         << endl;
    cout << "C: "
         << is_volatile<C>::value
         << endl;
    cout << "D: "
         << is_volatile<D>::value
         << endl;
    cout << "E: "
         << is_volatile<E>::value
         << endl;
    return 0;
checking volatileness:
A: true
B: true
C: true
D: true
E: false


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!