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