| title |
add_cv Class | Microsoft Docs |
| ms.custom |
|
| ms.date |
11/04/2016 |
| ms.reviewer |
|
| ms.suite |
|
| ms.technology |
|
| ms.tgt_pltfrm |
|
| ms.topic |
article |
| f1_keywords |
add_cv |
std::add_cv |
type_traits/std::add_cv |
|
| dev_langs |
|
| helpviewer_keywords |
|
| ms.assetid |
a5572c78-a097-45d7-b476-ed4876889dea |
| caps.latest.revision |
20 |
| author |
corob-msft |
| ms.author |
corob |
| manager |
ghogen |
| translation.priority.mt |
cs-cz |
de-de |
es-es |
fr-fr |
it-it |
ja-jp |
ko-kr |
pl-pl |
pt-br |
ru-ru |
tr-tr |
zh-cn |
zh-tw |
|
Makes const volatile type from type.
template <class T>
struct add_cv;
template <class T>
using add_cv_t = typename add_cv<T>::type;
T
The type to modify.
Remarks
An instance of the modified type add_cv<T> has a type member typedef equivalent to T modified by both add_volatile and add_const, unless T already has the cv-qualifiers, is a reference, or is a function.
The add_cv_t<T> helper type is a shortcut to access the add_cv<T> member typedef type.
// add_cv.cpp
// compile by using: cl /EHsc /W4 add_cv.cpp
#include <type_traits>
#include <iostream>
struct S {
void f() {
std::cout << "invoked non-cv-qualified S.f()" << std::endl;
}
void f() const {
std::cout << "invoked const S.f()" << std::endl;
}
void f() volatile {
std::cout << "invoked volatile S.f()" << std::endl;
}
void f() const volatile {
std::cout << "invoked const volatile S.f()" << std::endl;
}
};
template <class T>
void invoke() {
T t;
((T *)&t)->f();
}
int main()
{
invoke<S>();
invoke<std::add_const<S>::type>();
invoke<std::add_volatile<S>::type>();
invoke<std::add_cv<S>::type>();
}
invoked non-cv-qualified S.f()
invoked const S.f()
invoked volatile S.f()
invoked const volatile S.f()
Header: <type_traits>
Namespace: std
<type_traits>
remove_const Class
remove_volatile Class