1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// type_traits
10
11// is_null_pointer
12
13// UNSUPPORTED: c++03, c++11
14
15#include <type_traits>
16#include <cstddef> // for std::nullptr_t
17#include "test_macros.h"
18
19template <class T>
20void test_is_null_pointer()
21{
22 static_assert( std::is_null_pointer<T>::value, "");
23 static_assert( std::is_null_pointer<const T>::value, "");
24 static_assert( std::is_null_pointer<volatile T>::value, "");
25 static_assert( std::is_null_pointer<const volatile T>::value, "");
26#if TEST_STD_VER > 14
27 static_assert( std::is_null_pointer_v<T>, "");
28 static_assert( std::is_null_pointer_v<const T>, "");
29 static_assert( std::is_null_pointer_v<volatile T>, "");
30 static_assert( std::is_null_pointer_v<const volatile T>, "");
31#endif
32}
33
34template <class T>
35void test_is_not_null_pointer()
36{
37 static_assert(!std::is_null_pointer<T>::value, "");
38 static_assert(!std::is_null_pointer<const T>::value, "");
39 static_assert(!std::is_null_pointer<volatile T>::value, "");
40 static_assert(!std::is_null_pointer<const volatile T>::value, "");
41#if TEST_STD_VER > 14
42 static_assert(!std::is_null_pointer_v<T>, "");
43 static_assert(!std::is_null_pointer_v<const T>, "");
44 static_assert(!std::is_null_pointer_v<volatile T>, "");
45 static_assert(!std::is_null_pointer_v<const volatile T>, "");
46#endif
47}
48
49class Empty
50{
51};
52
53class NotEmpty
54{
55 virtual ~NotEmpty();
56};
57
58union Union {};
59
60struct bit_zero
61{
62 int : 0;
63};
64
65class Abstract
66{
67 virtual ~Abstract() = 0;
68};
69
70enum Enum {zero, one};
71struct incomplete_type;
72
73typedef void (*FunctionPtr)();
74
75int main(int, char**)
76{
77 test_is_null_pointer<std::nullptr_t>();
78
79 test_is_not_null_pointer<void>();
80 test_is_not_null_pointer<int>();
81 test_is_not_null_pointer<int&>();
82 test_is_not_null_pointer<int&&>();
83 test_is_not_null_pointer<int*>();
84 test_is_not_null_pointer<double>();
85 test_is_not_null_pointer<const int*>();
86 test_is_not_null_pointer<char[3]>();
87 test_is_not_null_pointer<char[]>();
88 test_is_not_null_pointer<Union>();
89 test_is_not_null_pointer<Enum>();
90 test_is_not_null_pointer<FunctionPtr>();
91 test_is_not_null_pointer<Empty>();
92 test_is_not_null_pointer<bit_zero>();
93 test_is_not_null_pointer<NotEmpty>();
94 test_is_not_null_pointer<Abstract>();
95 test_is_not_null_pointer<incomplete_type>();
96
97 return 0;
98}
99

source code of libcxx/test/std/utilities/meta/meta.unary/meta.unary.cat/is_null_pointer.pass.cpp