types_is_null_pointer

types_is_null_pointer (널 포인터 타입 판별)

std::is_null_pointer는 주어진 타입 Tstd::nullptr_t 타입인지 컴파일 타임에 확인하는 타입 특성(type trait)이에요. Tstd::nullptr_t(cv 한정 포함)라면 valuetrue가 되고, 그 외에는 false가 돼요. C++11부터 사용할 수 있어요.

출처: cppreference

본문

Defined in header <type_traits>
template < class T > struct is_null_pointer ; (since C++11)

std::is_null_pointer는 UnaryTypeTrait로, Tstd::nullptr_t 타입인지 확인해요.

Tstd::nullptr_t, const std::nullptr_t, volatile std::nullptr_t, 또는 const volatile std::nullptr_t 타입이라면 멤버 상수 valuetrue가 되고, 그 외의 경우에는 false가 돼요.

프로그램에서 std::is_null_pointer 또는 std::is_null_pointer_v(C++17부터)에 대한 특수화를 추가하면 동작이 정의되지 않아요.

템플릿 매개변수

T - 확인할 타입

헬퍼 변수 템플릿

template < class T > constexpr bool is_null_pointer_v = is_null_pointer < T >:: value ; (since C++17)

std::integral_constant에서 상속받은 구성 요소

멤버 상수

value [static] Tstd::nullptr_t 타입(cv 한정 포함)이면 true, 아니면 false (공용 정적 멤버 상수)

멤버 함수

operator bool 객체를 bool로 변환하고 value를 반환해요 (공용 멤버 함수)
operator() (C++14) value를 반환해요 (공용 멤버 함수)

멤버 타입

Type Definition
value_type bool
type std :: integral_constant < bool , value >

가능한 구현

template < class T > struct is_null_pointer : std :: is_same < std :: nullptr_t , std :: remove_cv_t < T >> {};

참고 사항

std::nullptr_t는 내장 포인터 타입이 아니기 때문에 std::is_pointerstd::nullptr_t에 대해 false를 반환해요.

libc++에서는 std::is_null_pointer가 C++11 모드에서 제공되지 않아요.

Feature-test macro Value Std Feature
__cpp_lib_is_null_pointer 201309L (C++14) (DR11) std::is_null_pointer

예제

#include <type_traits>

static_assert(std::is_null_pointer_v<decltype(nullptr)>);
static_assert(!std::is_null_pointer_v<int*>);
static_assert(!std::is_pointer_v<decltype(nullptr)>);
static_assert(std::is_pointer_v<int*>);

int main()
{
}

결함 보고

다음의 동작 변경 결함 보고는 이전에 발표된 C++ 표준에 소급 적용되었어요.

DR Applied to Behavior as published Correct behavior
LWG 2247 C++11 std::nullptr_t를 감지하는 타입 특성이 없었음 추가됨

같이 보기

is_void (C++11) 타입이 void인지 확인해요 (클래스 템플릿) [edit]
is_array (C++11) 타입이 배열 타입인지 확인해요 (클래스 템플릿) [edit]
is_pointer (C++11) 타입이 포인터 타입인지 확인해요 (클래스 템플릿) [edit]
is_enum (C++11) 타입이 열거형 타입인지 확인해요 (클래스 템플릿) [edit]
is_union (C++11) 타입이 공용체 타입인지 확인해요 (클래스 템플릿) [edit]
is_class (C++11) 타입이 비공용체 클래스 타입인지 확인해요 (클래스 템플릿) [edit]
is_function (C++11) 타입이 함수 타입인지 확인해요 (클래스 템플릿) [edit]
is_object (C++11) 타입이 객체 타입인지 확인해요 (클래스 템플릿) [edit]
is_null_pointer_type (C++26) 반영된 타입이 std::nullptr_t인지 확인해요 (함수) [edit]

더 알아보기 (Learn more)

cppreference