std::add_cv, std::add_const, std::add_volatile

Header: <type_traits>

Provides the member typedef type which is the same as T, except it has a cv-qualifier added (unless T is a function, a reference, or already has this cv-qualifier)

# Declarations

template< class T >
struct add_cv;

(since C++11)

template< class T >
struct add_const;

(since C++11)

template< class T >
struct add_volatile;

(since C++11)

# Notes

These transformation traits can be used to establish non-deduced contexts in template argument deduction:

# Example

#include <iostream>
#include <type_traits>
 
struct foo
{
    void m() { std::cout << "Non-cv\n"; }
    void m() const { std::cout << "Const\n"; }
    void m() volatile { std::cout << "Volatile\n"; }
    void m() const volatile { std::cout << "Const-volatile\n"; }
};
 
int main()
{
    foo{}.m();
    std::add_const<foo>::type{}.m();
    std::add_volatile<foo>::type{}.m();
    std::add_cv<foo>::type{}.m();
}

# See also