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
, the topmost volatile
, or both, if present.
2) removes the topmost const
.
3) removes the topmost volatile
.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <iostream> #include <type_traits> int main() { typedef std::remove_cv< const int >::type type1; typedef std::remove_cv< volatile int >::type type2; typedef std::remove_cv< const volatile int >::type type3; typedef std::remove_cv< const volatile int *>::type type4; typedef std::remove_cv< int * const volatile >::type type5; std::cout << "test1 " << (std::is_same< int , type1>::value ? "passed" : "failed" ) << '\n' ; std::cout << "test2 " << (std::is_same< int , type2>::value ? "passed" : "failed" ) << '\n' ; std::cout << "test3 " << (std::is_same< int , type3>::value ? "passed" : "failed" ) << '\n' ; std::cout << "test4 " << (std::is_same< const volatile int *, type4>::value ? "passed" : "failed" ) << '\n' ; std::cout << "test5 " << (std::is_same< int *, type5>::value ? "passed" : "failed" ) << '\n' ; } |
Output:
1 2 3 4 5 | test1 passed test2 passed test3 passed test4 passed test5 passed |
See also
(C++11) | checks if a type is const-qualified (class template) |
(C++11) | checks if a type is volatile-qualified (class template) |
Please login to continue.