Skip to content
Related Articles
Open in App
Not now

Related Articles

std::add_cv in C++ with Examples

Improve Article
Save Article
Like Article
  • Last Updated : 12 Jun, 2020
Improve Article
Save Article
Like Article

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:


Template Class:

template< class T >
struct add_cv



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++:


// 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;
        << "D: "
        << is_volatile<D>::value
        << endl;
    return 0;


typedefs of const volatile int:
A: true
B: true
C: true
D: true


My Personal Notes arrow_drop_up
Like Article
Save Article
Related Articles

Start Your Coding Journey Now!