GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::add_cv,std::add_const,std::add_volatile(3) C++ Standard Libary std::add_cv,std::add_const,std::add_volatile(3)

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


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)


1) adds both const and volatile
2) adds const
3) adds volatile


The behavior of a program that adds specializations for any of the templates
described on this page is undefined.


Name Definition
type the type T with the cv-qualifier


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;


template<class T> struct add_cv { typedef const volatile T type; };


template<class T> struct add_const { typedef const T type; };


template<class T> struct add_volatile { typedef volatile T type; };


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


template<class T>
void f(const T&, const T&);


template<class T>
void g(const T&, std::add_const_t<T>&);


f(4.2, 0); // error, deduced conflicting types for 'T'
g(4.2, 0); // OK, calls g<double>

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


Non-cv
Const
Volatile
Const-volatile


is_const checks if a type is const-qualified
(C++11) (class template)
is_volatile checks if a type is volatile-qualified
(C++11) (class template)
remove_cv
remove_const
remove_volatile removes const or/and volatile specifiers from the given type
(C++11) (class template)
(C++11)
(C++11)
as_const obtains a reference to const to its argument
(C++17) (function template)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.