The std::add_cv template of C++ STL is present in the <type_traits> header file. The std::add_cv template of C++ STL is used to get the type T with const and volatile qualification. The function std::is_same::value is used to check whether T is a const and volatile qualification or not.
Header File:
#include<type_traits>
Template Class:
template< class T > struct add_cv
Syntax:
std::add_const::type
Parameter: The template std::add_cv accepts a single parameter T(Trait class) to check whether T is const and volatile qualified or not.
Below is the program to demonstrate std::add_cv in C++:
Program:
// C++ program to illustrate // std::add_cv #include <bits/stdc++.h> #include <type_traits> using namespace std; // Driver Code int main() { // Declare variables of int, const, // volatile, const volatile using add_cv typedef add_cv<int>::type A; typedef add_cv<const int>::type B; typedef add_cv<volatile int>::type C; typedef add_cv<const volatile int>::type D; cout << boolalpha; // Check the type of variable declared // above is volatile or not 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; return 0; } |
typedefs of const volatile int: A: true B: true C: true D: true
Reference: http://www.cplusplus.com/reference/type_traits/add_cv/
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- ratio_equal() in C++ with examples
- std::allocator() in C++ with Examples
- ratio_not_equal() in C++ with examples
- std::bit_or in C++ with Examples
- iswprint() in C/C++ with Examples
- iswgraph() in C/C++ with Examples
- mbrtoc16() in C/C++ with Examples
- mbrtoc32() in C/C++ with Examples
- wmemset() in C/C++ with Examples
- wcsspn() function in C/C++ with Examples
- Commonly used String functions in C/C++ with Examples
- std::string::front() in C++with Examples
- std::string::back() in C++ with Examples
- std::uniform_int_distribution reset() method in C++ with examples
- std::uniform_int_distribution min() method in C++ with examples
- std::uniform_int_distribution a() method in C++ with examples
- std::uniform_int_distribution max() method in C++ with examples
- std::uniform_int_distribution b() method in C++ with examples
- std::uniform_real_distribution b() method in C++ with Examples
- std::uniform_real_distribution min() method in C++ with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

