std::remove_cv, std::remove_const, std::remove_volatile
De cppreference.com
![]() | This page has been machine-translated from the English version of the wiki using Google Translate. The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
Déclaré dans l'en-tête <type_traits> | ||
template<class T > struct remove_cv; | (1) | (depuis C++11) |
template<class T > struct remove_const; | (2) | (depuis C++11) |
template<class T > struct remove_volatile; | (3) | (depuis 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
Sommaire |
[modifier]Types de membres
Nom Original: Name The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | Definition |
type | the type T without cv-qualifier |
[modifier]Mise en œuvre possible
template<class T >struct remove_cv {typedeftypename std::remove_volatile<typename std::remove_const<T>::type>::type 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;}; |
[modifier]Exemple
Removing const/volatile from constvolatileint* does not modify the type, because the pointer itself is neither const nor volatile.
#include <iostream>#include <type_traits> int main(){typedef std::remove_cv<constint>::type type1;typedef std::remove_cv<volatileint>::type type2;typedef std::remove_cv<constvolatileint>::type type3;typedef std::remove_cv<constvolatileint*>::type type4;typedef std::remove_cv<int*constvolatile>::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<constvolatileint*, type4>::value?"passed":"failed")<<'\n';std::cout<<"test5 "<<(std::is_same<int*, type5>::value?"passed":"failed")<<'\n';}
Résultat :
test1 passed test2 passed test3 passed test4 passed test5 passed
[modifier]Voir aussi
(C++11) | vérifie si un type est const qualifié Original: checks if a type is const-qualified The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (classe générique) |
(C++11) | vérifie si un type est volatile qualifié Original: checks if a type is volatile-qualified The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (classe générique) |