blob: cb5849f45f315b39596930cf3258216b05a5c7c9 [file] [log] [blame]
Marshall Clow94611a82015-11-01 20:24:59 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// type_traits
11
12// is_function
13
14#include <type_traits>
Marshall Clow55d741c2015-11-10 15:48:23 +000015#include <cstddef> // for std::nullptr_t
Marshall Clow94611a82015-11-01 20:24:59 +000016#include "test_macros.h"
17
18template <class T>
19void test_is_function()
20{
21 static_assert( std::is_function<T>::value, "");
22 static_assert( std::is_function<const T>::value, "");
23 static_assert( std::is_function<volatile T>::value, "");
24 static_assert( std::is_function<const volatile T>::value, "");
25#if TEST_STD_VER > 14
26 static_assert( std::is_function_v<T>, "");
27 static_assert( std::is_function_v<const T>, "");
28 static_assert( std::is_function_v<volatile T>, "");
29 static_assert( std::is_function_v<const volatile T>, "");
30#endif
31}
32
33template <class T>
34void test_is_not_function()
35{
36 static_assert(!std::is_function<T>::value, "");
37 static_assert(!std::is_function<const T>::value, "");
38 static_assert(!std::is_function<volatile T>::value, "");
39 static_assert(!std::is_function<const volatile T>::value, "");
40#if TEST_STD_VER > 14
41 static_assert(!std::is_function_v<T>, "");
42 static_assert(!std::is_function_v<const T>, "");
43 static_assert(!std::is_function_v<volatile T>, "");
44 static_assert(!std::is_function_v<const volatile T>, "");
45#endif
46}
47
48class Empty
49{
50};
51
52class NotEmpty
53{
54 virtual ~NotEmpty();
55};
56
57union Union {};
58
59struct bit_zero
60{
61 int : 0;
62};
63
64class Abstract
65{
66 virtual ~Abstract() = 0;
67};
68
69enum Enum {zero, one};
Marshall Clow7490f532016-02-25 20:15:47 +000070struct incomplete_type;
Marshall Clow94611a82015-11-01 20:24:59 +000071
72typedef void (*FunctionPtr)();
73
74int main()
75{
76 test_is_function<void(void)>();
77 test_is_function<int(int)>();
78 test_is_function<int(int, double)>();
79 test_is_function<int(Abstract *)>();
80 test_is_function<void(...)>();
81
82 test_is_not_function<std::nullptr_t>();
83 test_is_not_function<void>();
84 test_is_not_function<int>();
85 test_is_not_function<int&>();
86 test_is_not_function<int&&>();
87 test_is_not_function<int*>();
88 test_is_not_function<double>();
89 test_is_not_function<char[3]>();
90 test_is_not_function<char[]>();
91 test_is_not_function<Union>();
92 test_is_not_function<Enum>();
93 test_is_not_function<FunctionPtr>(); // function pointer is not a function
94 test_is_not_function<Empty>();
95 test_is_not_function<bit_zero>();
96 test_is_not_function<NotEmpty>();
97 test_is_not_function<Abstract>();
98 test_is_not_function<Abstract*>();
Marshall Clow7490f532016-02-25 20:15:47 +000099 test_is_not_function<incomplete_type>();
Marshall Clow94611a82015-11-01 20:24:59 +0000100}