Open In App

std::remove_volatile in C++ with Examples

Improve
Improve
Like Article
Like
Save
Share
Report

The std::remove_volatile template of C++ STL is present in the <type_traits> header file. The std::remove_volatile template of C++ STL is used to get the T without volatile qualification. It return the boolean value true if T is without volatile qualified, otherwise return false. Below is the syntax for the same:

Header File:

#include<type_traits>

Template Class:

template <class <T>
struct remove_volatile;

Syntax:

std::remove_volatile::value

Parameter: The template std::rmeove_volatile accepts a single parameter T(Trait class) to check whether T is without volatile qualified or not.

Return Value: The template std::remove_volatile returns a boolean value:

  • True: If type T is without volatile qualified.
  • False: If type T is with volatile qualified.

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

Program 1:




// C++ program to illustrate
// std::remove_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 remove_volatile<int>::type A;
    typedef remove_volatile<volatile int>::type B;
    typedef remove_volatile<int* volatile>::type C;
    typedef remove_volatile<volatile int*>::type D;
    typedef remove_volatile<volatile int&>::type E;
  
    cout << boolalpha;
  
    // Checking the non-volatileness
    // of the above declared variable
    cout << "checking Non-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;
}


Output:

checking Non-volatileness:
A: false
B: false
C: false
D: false
E: false

Program 2:




// C++ program to illustrate
// std::remove_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 remove_cv<float>::type a;
    typedef remove_cv<char* const>::type b;
    typedef remove_cv<const char*>::type c;
  
    cout << boolalpha;
  
    // Checking the non-volatileness
    // of the above declared variable
    cout << "checking Non-volatileness:"
         << endl;
  
    cout << "A: "
         << is_volatile<A>::value
         << endl;
  
    cout << "B: "
         << is_volatile<B>::value
         << endl;
  
    cout << "C: "
         << is_volatile<a>::value
         << endl;
  
    cout << "D: "
         << is_volatile<b>::value
         << endl;
  
    cout << "E: "
         << is_volatile<c>::value
         << endl;
  
    return 0;
}


Output:

checking Non-volatileness:
A: true
B: true
C: false
D: false
E: false

Reference: http://www.cplusplus.com/reference/type_traits/remove_volatile/



Last Updated : 24 Jul, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads