std::remove_volatile in C++ with Examples
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:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
int main()
{
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;
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:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
int main()
{
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;
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
Share your thoughts in the comments
Please Login to comment...