Namespaces
Variants

std:: is_pointer

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
(C++11)
is_pointer
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++14)
(C++11) (deprecated in C++26)
(C++11) ( until C++20* )
(C++11) (deprecated in C++20)
(C++11)
Type trait constants
Metafunctions
(C++17)
Supported operations
Relationships and property queries
Type modifications
Type transformations
(C++11) (deprecated in C++23)
(C++11) (deprecated in C++23)
(C++11)
(C++11) ( until C++20* ) (C++17)

Compile-time rational arithmetic
Compile-time integer sequences
헤더 파일에 정의됨 <type_traits>
template < class T >
struct is_pointer ;
(C++11부터)

std::is_pointer UnaryTypeTrait 입니다.

T 객체 또는 함수에 대한 포인터 (멤버 포인터는 제외하고 void 포인터 포함) 또는 이의 cv-qualified 버전인지 확인합니다. T 가 객체/함수 포인터 타입일 경우 멤버 상수 value true 와 동일한 값을 제공합니다. 그렇지 않으면 value false 와 동일합니다.

프로그램이 std::is_pointer std::is_pointer_v 에 대한 특수화를 추가하는 경우, 그 동작은 정의되지 않습니다.

목차

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

template < class T >
constexpr bool is_pointer_v = is_pointer < T > :: value ;
(C++17부터)

std:: integral_constant 로부터 상속됨

멤버 상수

value
[static]
true 만약 T 가 포인터 타입이면, false 그렇지 않으면
(public static member constant)

멤버 함수

operator bool
객체를 bool 로 변환, value 반환
(public member function)
operator()
(C++14)
value 반환
(public member function)

멤버 타입

타입 정의
value_type bool
type std:: integral_constant < bool , value >

가능한 구현

template<class T>
struct is_pointer : std::false_type {};
template<class T>
struct is_pointer<T*> : std::true_type {};
template<class T>
struct is_pointer<T* const> : std::true_type {};
template<class T>
struct is_pointer<T* volatile> : std::true_type {};
template<class T>
struct is_pointer<T* const volatile> : std::true_type {};
**참고:** 제공된 HTML 코드 블록 내의 모든 텍스트는 C++ 코드이므로 번역에서 제외되었습니다. HTML 태그와 속성, 그리고 `
` 태그 내의 C++ 코드는 원본 그대로 유지되었습니다.

예제

#include <type_traits>
int main()
{
    struct A
    {
        int m;
        void f() {}
    };
    int A::*mem_data_ptr = &A::m;     // 멤버 데이터에 대한 포인터
    void (A::*mem_fun_ptr)() = &A::f; // 멤버 함수에 대한 포인터
    static_assert(
           ! std::is_pointer<A>::value
        && ! std::is_pointer_v<A>    // 위와 동일하지만 C++17에서!
        && ! std::is_pointer<A>()    // 위와 동일, 상속된 operator bool 사용
        && ! std::is_pointer<A>{}    // 동일
        && ! std::is_pointer<A>()()  // 위와 동일, 상속된 operator() 사용
        && ! std::is_pointer<A>{}()  // 동일
        &&   std::is_pointer_v<A*>
        &&   std::is_pointer_v<A const* volatile>
        && ! std::is_pointer_v<A&>
        && ! std::is_pointer_v<decltype(mem_data_ptr)>
        && ! std::is_pointer_v<decltype(mem_fun_ptr)>
        &&   std::is_pointer_v<void*>
        && ! std::is_pointer_v<int>
        &&   std::is_pointer_v<int*>
        &&   std::is_pointer_v<int**>
        && ! std::is_pointer_v<int[10]>
        && ! std::is_pointer_v<std::nullptr_t>
        &&   std::is_pointer_v<void (*)()>
    );
}

참고 항목

타입이 비정적 멤버 함수 또는 객체에 대한 포인터인지 확인
(클래스 템플릿)
타입이 비정적 멤버 객체 포인터인지 확인
(클래스 템플릿)
타입이 비정적 멤버 함수 포인터인지 확인
(클래스 템플릿)
(C++11)
타입이 배열 타입인지 확인
(클래스 템플릿)
(C++11)
타입이 스칼라 타입인지 확인
(클래스 템플릿)