std:: remove_cv, std:: remove_const, std:: remove_volatile
From cppreference.net
C++
Metaprogramming library
| Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
(C++14)
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<type_traits>
|
||
|
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부터) |
멤버 typedef
type
를 제공합니다. 이는
T
와 동일하지만, 최상위 cv-qualifier가 제거된 타입입니다.
1)
최상위
const
또는 최상위
volatile
한정자를 제거합니다. 둘 다 존재하는 경우 모두 제거합니다.
2)
최상위
const
를 제거합니다.
3)
최상위
volatile
를 제거합니다.
프로그램이 이 페이지에 설명된 템플릿들 중 어느 하나에 대해 특수화를 추가하는 경우, 동작은 정의되지 않습니다.
목차 |
멤버 타입
| 이름 | 정의 |
type
|
cv 한정자가 없는
T
타입
|
헬퍼 타입
|
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; }; |
태그 내에 포함된 C++ 코드만 존재하며, 번역이 필요한 일반 텍스트는 포함되어 있지 않습니다. 지시사항에 따라 C++ 코드는 번역하지 않고 원본을 그대로 유지했습니다.
예제
const volatile int * 에서 const/volatile을 제거해도 타입을 수정하지 않습니다. 왜냐하면 포인터 자체는 const도 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() {}
참고 항목
|
(C++11)
|
타입이 const 한정자인지 검사합니다
(class template) |
|
(C++11)
|
타입이 volatile 한정자인지 검사합니다
(class template) |
|
(C++11)
(C++11)
(C++11)
|
주어진 타입에
const
및/또는
volatile
지정자를 추가합니다
(class template) |
|
(C++20)
|
std::remove_cv
와
std::remove_reference
를 결합합니다
(class template) |