1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
/*=============================================================================
Copyright (c) 2017 Paul Fultz II
is_invocable.cpp
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#include <boost/hof/is_invocable.hpp>
#include <ciso646>
#include "test.hpp"
template<int N>
struct callable_rank : callable_rank<N-1>
{};
template<>
struct callable_rank<0>
{};
BOOST_HOF_STATIC_TEST_CASE()
{
struct is_callable_class
{
void operator()(int) const
{
}
};
struct callable_test_param {};
void is_callable_function(int)
{
}
struct is_callable_rank_class
{
void operator()(int, callable_rank<3>) const
{
}
void operator()(int, callable_rank<4>) const
{
}
};
static_assert(boost::hof::is_invocable<is_callable_class, int>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_class, long>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_class, double>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_class, const int&>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_class, const long&>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_class, const double&>::value, "Not callable");
static_assert(not boost::hof::is_invocable<is_callable_class, callable_test_param>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_class>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_class, int, int>::value, "callable failed");
typedef void (*is_callable_function_pointer)(int);
static_assert(boost::hof::is_invocable<is_callable_function_pointer, int>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_function_pointer, long>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_function_pointer, double>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_function_pointer, const int&>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_function_pointer, const long&>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_function_pointer, const double&>::value, "Not callable");
static_assert(not boost::hof::is_invocable<is_callable_function_pointer, callable_test_param>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_function_pointer>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_function_pointer, int, int>::value, "callable failed");
static_assert(boost::hof::is_invocable<is_callable_rank_class, int, callable_rank<3>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, long, callable_rank<3>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, double, callable_rank<3>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const int&, callable_rank<3>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const long&, callable_rank<3>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const double&, callable_rank<3>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, int, callable_rank<4>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, long, callable_rank<4>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, double, callable_rank<4>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const int&, callable_rank<4>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const long&, callable_rank<4>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const double&, callable_rank<4>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, int, callable_rank<5>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, long, callable_rank<5>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, double, callable_rank<5>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const int&, callable_rank<5>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const long&, callable_rank<5>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const double&, callable_rank<5>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, int, callable_rank<6>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, long, callable_rank<6>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, double, callable_rank<6>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const int&, callable_rank<6>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const long&, callable_rank<6>>::value, "Not callable");
static_assert(boost::hof::is_invocable<is_callable_rank_class, const double&, callable_rank<6>>::value, "Not callable");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, int, callable_rank<1>>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, long, callable_rank<1>>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, double, callable_rank<1>>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, const int&, callable_rank<1>>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, const long&, callable_rank<1>>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, const double&, callable_rank<1>>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, callable_test_param, callable_test_param>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, callable_rank<3>, callable_test_param>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, callable_rank<4>, callable_test_param>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, callable_test_param, callable_rank<3>>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, callable_test_param, callable_rank<4>>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class>::value, "callable failed");
static_assert(not boost::hof::is_invocable<is_callable_rank_class, int, int>::value, "callable failed");
};
BOOST_HOF_STATIC_TEST_CASE()
{
typedef int(callable_rank<0>::*fn)(int);
static_assert(boost::hof::is_invocable<fn, callable_rank<0>&, int>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, callable_rank<1>&, int>::value, "Failed");
static_assert(!boost::hof::is_invocable<fn, callable_rank<0>&>::value, "Failed");
static_assert(!boost::hof::is_invocable<fn, callable_rank<0> const&, int>::value, "Failed");
};
BOOST_HOF_STATIC_TEST_CASE()
{
typedef int(callable_rank<0>::*fn)(int);
typedef callable_rank<0>* T;
typedef callable_rank<1>* DT;
typedef const callable_rank<0>* CT;
typedef std::unique_ptr<callable_rank<0>> ST;
static_assert(boost::hof::is_invocable<fn, T&, int>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, DT&, int>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, const T&, int>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, T&&, int>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, ST, int>::value, "Failed");
static_assert(!boost::hof::is_invocable<fn, CT&, int>::value, "Failed");
};
BOOST_HOF_STATIC_TEST_CASE()
{
typedef int(callable_rank<0>::*fn);
static_assert(!boost::hof::is_invocable<fn>::value, "Failed");
};
BOOST_HOF_STATIC_TEST_CASE()
{
typedef int(callable_rank<0>::*fn);
static_assert(boost::hof::is_invocable<fn, callable_rank<0>&>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, callable_rank<0>&&>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, const callable_rank<0>&>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, callable_rank<1>&>::value, "Failed");
};
BOOST_HOF_STATIC_TEST_CASE()
{
typedef int(callable_rank<0>::*fn);
typedef callable_rank<0>* T;
typedef callable_rank<1>* DT;
typedef const callable_rank<0>* CT;
typedef std::unique_ptr<callable_rank<0>> ST;
static_assert(boost::hof::is_invocable<fn, T&>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, DT&>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, const T&>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, T&&>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, ST>::value, "Failed");
static_assert(boost::hof::is_invocable<fn, CT&>::value, "Failed");
};
BOOST_HOF_STATIC_TEST_CASE()
{
typedef void(*fp)(callable_rank<0>&, int);
static_assert(boost::hof::is_invocable<fp, callable_rank<0>&, int>::value, "Failed");
static_assert(boost::hof::is_invocable<fp, callable_rank<1>&, int>::value, "Failed");
static_assert(!boost::hof::is_invocable<fp, const callable_rank<0>&, int>::value, "Failed");
static_assert(!boost::hof::is_invocable<fp>::value, "Failed");
static_assert(!boost::hof::is_invocable<fp, callable_rank<0>&>::value, "Failed");
};
BOOST_HOF_STATIC_TEST_CASE()
{
typedef void(&fp)(callable_rank<0>&, int);
static_assert(boost::hof::is_invocable<fp, callable_rank<0>&, int>::value, "Failed");
static_assert(boost::hof::is_invocable<fp, callable_rank<1>&, int>::value, "Failed");
static_assert(!boost::hof::is_invocable<fp, const callable_rank<0>&, int>::value, "Failed");
static_assert(!boost::hof::is_invocable<fp>::value, "Failed");
static_assert(!boost::hof::is_invocable<fp, callable_rank<0>&>::value, "Failed");
};
|