[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/types/remove_cv [Back]  [Original]

std::remove_cv, std::remove_const, std::remove_volatile cppreference.com
cppreference.com

std::remove_cv, std::remove_const, std::remove_volatile

cppreference.com
 
C++
(C++20)
(C++20)
(C++11)
(C++20)
/
(C++11)
(C++11)
(C++11)
(C++17)
 
(C++11)
(C++14)  
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++14)
(C++11)
(C++11)( C++20*)
(C++11)( C++20)
(C++11)
(C++17)
(C++11)(C++11)(C++11)
(C++11)( C++23)
(C++11)( C++23)
(C++11)
(C++11)
(C++17)

(C++11)( C++20*)(C++17)
 
<tbody> </tbody>
template< class T > struct remove_cv;
(1) ( C++11)
template< class T > struct remove_const;
(2) ( C++11)
template< class T > struct remove_volatile;
(3) ( C++11)

type, T, , cv- .

1) const, volatile, ,
2) const
3) volatile

, , .

-

type T cv-

<tbody> </tbody>
template< class T > using remove_cv_t = typename remove_cv<T>::type;
( C++14)
template< class T > using remove_const_t = typename remove_const<T>::type;
( C++14)
template< class T > using remove_volatile_t = typename remove_volatile<T>::type;
( 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<const volatile 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; };

const/volatile const volatile int * , const, volatile .

#include <iostream>
#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 >
    and same< std::remove_cv_t< const int >, int >
    and same< std::remove_cv_t< volatile int >, int >
    and same< std::remove_cv_t< const volatile int >, int >
    // remove_cv    ,    
    not same<std::remove_cv_t<const volatile int*>, int*> &&
    and same< std::remove_cv_t< const volatile int* >, const volatile int* >
    and same< std::remove_cv_t< const int* volatile >, const int* >
    and same< std::remove_cv_t< int* const volatile >, int* >
);

int main() {}

(C++11)
, const
( ) []
, volatile
( ) []
(C++11)(C++11)(C++11)
const / volatile
( ) []
std::remove_cv std::remove_reference
( ) []

Web Proxy Viewer  |  New URL  |  Original Page