On this page
std::remove_cv, std::remove_const, std::remove_volatile
Defined in header <type_traits> |
||
---|---|---|
|
(1) | (since C++11) |
|
(2) | (since C++11) |
|
(3) | (since C++11) |
Provides the member typedef type
which is the same as T
, except that its topmost cv-qualifiers are removed.
1) Removes the topmost
const
, or the topmost volatile
, or both, if present.
2) Removes the topmost
const
.
3) Removes the topmost
volatile
.
The behavior of a program that adds specializations for any of the templates described on this page is undefined.
Member types
Name | Definition |
---|---|
type |
the type T without cv-qualifier |
Helper types
|
(since C++14) | |
|
(since C++14) | |
|
(since C++14) |
Possible implementation
|
Example
Removing const/volatile from const volatile int*
does not modify the type, because the pointer itself is neither const nor volatile.
#include <type_traits>
template<typename U, typename V>
constexpr bool same = std::is_same_v<U, V>;
static_assert
(
same<std::remove_cv_t<int>, int> &&
same<std::remove_cv_t<const int>, int> &&
same<std::remove_cv_t<volatile int>, int> &&
same<std::remove_cv_t<const volatile int>, int> &&
// remove_cv only works on types, not on pointers
not same<std::remove_cv_t<const volatile int*>, int*> &&
same<std::remove_cv_t<const volatile int*>, const volatile int*> &&
same<std::remove_cv_t<const int* volatile>, const int*> &&
same<std::remove_cv_t<int* const volatile>, int*>
);
int main() {}
See also
(C++11)
|
checks if a type is const-qualified (class template) |
(C++11)
|
checks if a type is volatile-qualified (class template) |
(C++11)(C++11)(C++11)
|
adds const and/or volatile specifiers to the given type (class template) |
(C++20)
|
combines std::remove_cv and std::remove_reference (class template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/types/remove_cv