Skip to content

Latest commit

 

History

History
93 lines (79 loc) · 2.19 KB

add-cv-class.md

File metadata and controls

93 lines (79 loc) · 2.19 KB
title ms.custom ms.date ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic f1_keywords dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
add_cv Class | Microsoft Docs
11/04/2016
cpp-standard-libraries
article
type_traits/std::add_cv
C++
add_cv class
add_cv
a5572c78-a097-45d7-b476-ed4876889dea
20
corob-msft
corob
ghogen

add_cv Class

Makes const volatile type from type.

Syntax

template <class T>  
struct add_cv;  
 
template <class T>
using add_cv_t = typename add_cv<T>::type;  

Parameters

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.

Example

// 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()  

Requirements

Header: <type_traits>
Namespace: std

See Also

<type_traits>
remove_const Class
remove_volatile Class