stdadd_cvstdadd_conststdadd_volatile(3)
std::add_cv,std::add_const,std::add_volatile - std::add_cv,std::add_const,std::add_volatile
Synopsis
Defined in header<type_traits>
template <class T>
(1)(since C++ 11)
struct add_cv;
template <class T>
(2)(since C++ 11)
struct add_const;
template <class T>
(3)(since C++ 11)
struct add_volatile;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)
- adds both const and volatile
- adds const
- adds volatile
Member types
Name Definition type the type T with the cv-qualifier
Helper types
template< class T > (since C++14) using add_cv_t = typename add_cv<T>::type; template< class T > (since C++14) using add_const_t = typename add_const<T>::type; template< class T > (since C++14) using add_volatile_t = typename add_volatile<T>::type;
Possible implementation
Example
// Run this code
#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();
}
Output:
See also
is_const checks if a type is const-qualified