Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++14) |
Defined in header <type_traits> | ||
template<class T> struct remove_cv; | (1) | (since C++11) |
template<class T> struct remove_const; | (2) | (since C++11) |
template<class T> struct remove_volatile; | (3) | (since C++11) |
Provides the member typedeftype
which is the same asT
, except that its topmost cv-qualifiers are removed.
If the program adds specializations for any of the templates described on this page, the behavior is undefined.
Contents |
Name | Definition |
type | the typeT without cv-qualifier |
template<class T> using remove_cv_t=typename remove_cv<T>::type; | (since C++14) | |
template<class T> using remove_const_t=typename remove_const<T>::type; | (since C++14) | |
template<class T> using remove_volatile_t=typename remove_volatile<T>::type; | (since C++14) | |
template<class T>struct remove_cv{typedef T type;};template<class T>struct remove_cv<const T>{typedef T type;};template<class T>struct remove_cv<volatile T>{typedef T type;};template<class T>struct remove_cv<constvolatile T>{typedef T type;}; template<class T>struct remove_const{typedef T type;};template<class T>struct remove_const<const T>{typedef T type;}; template<class T>struct remove_volatile{typedef T type;};template<class T>struct remove_volatile<volatile T>{typedef T type;}; |
Removing const/volatile fromconstvolatileint* does not modify the type, because the pointer itself is neither const nor volatile.
#include <type_traits> template<typename U,typename V>constexprbool same=std::is_same_v<U, V>; static_assert( same<std::remove_cv_t<int>,int>&& same<std::remove_cv_t<constint>,int>&& same<std::remove_cv_t<volatileint>,int>&& same<std::remove_cv_t<constvolatileint>,int>&&// remove_cv only works on types, not on pointers not same<std::remove_cv_t<constvolatileint*>,int*>&& same<std::remove_cv_t<constvolatileint*>,constvolatileint*>&& same<std::remove_cv_t<constint*volatile>,constint*>&& same<std::remove_cv_t<int*constvolatile>,int*>); int main(){}
(C++11) | checks if a type is const-qualified (class template)[edit] |
(C++11) | checks if a type is volatile-qualified (class template)[edit] |
(C++11)(C++11)(C++11) | addsconst and/orvolatile specifiers to the given type (class template)[edit] |
(C++20) | combinesstd::remove_cv andstd::remove_reference (class template)[edit] |