is_invocable.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. template<int N>
  11. struct callable_rank : callable_rank<N-1>
  12. {};
  13. template<>
  14. struct callable_rank<0>
  15. {};
  16. BOOST_HOF_STATIC_TEST_CASE()
  17. {
  18. struct is_callable_class
  19. {
  20. void operator()(int) const
  21. {
  22. }
  23. };
  24. struct callable_test_param {};
  25. void is_callable_function(int)
  26. {
  27. }
  28. struct is_callable_rank_class
  29. {
  30. void operator()(int, callable_rank<3>) const
  31. {
  32. }
  33. void operator()(int, callable_rank<4>) const
  34. {
  35. }
  36. };
  37. static_assert(boost::hof::is_invocable<is_callable_class, int>::value, "Not callable");
  38. static_assert(boost::hof::is_invocable<is_callable_class, long>::value, "Not callable");
  39. static_assert(boost::hof::is_invocable<is_callable_class, double>::value, "Not callable");
  40. static_assert(boost::hof::is_invocable<is_callable_class, const int&>::value, "Not callable");
  41. static_assert(boost::hof::is_invocable<is_callable_class, const long&>::value, "Not callable");
  42. static_assert(boost::hof::is_invocable<is_callable_class, const double&>::value, "Not callable");
  43. static_assert(not boost::hof::is_invocable<is_callable_class, callable_test_param>::value, "callable failed");
  44. static_assert(not boost::hof::is_invocable<is_callable_class>::value, "callable failed");
  45. static_assert(not boost::hof::is_invocable<is_callable_class, int, int>::value, "callable failed");
  46. typedef void (*is_callable_function_pointer)(int);
  47. static_assert(boost::hof::is_invocable<is_callable_function_pointer, int>::value, "Not callable");
  48. static_assert(boost::hof::is_invocable<is_callable_function_pointer, long>::value, "Not callable");
  49. static_assert(boost::hof::is_invocable<is_callable_function_pointer, double>::value, "Not callable");
  50. static_assert(boost::hof::is_invocable<is_callable_function_pointer, const int&>::value, "Not callable");
  51. static_assert(boost::hof::is_invocable<is_callable_function_pointer, const long&>::value, "Not callable");
  52. static_assert(boost::hof::is_invocable<is_callable_function_pointer, const double&>::value, "Not callable");
  53. static_assert(not boost::hof::is_invocable<is_callable_function_pointer, callable_test_param>::value, "callable failed");
  54. static_assert(not boost::hof::is_invocable<is_callable_function_pointer>::value, "callable failed");
  55. static_assert(not boost::hof::is_invocable<is_callable_function_pointer, int, int>::value, "callable failed");
  56. static_assert(boost::hof::is_invocable<is_callable_rank_class, int, callable_rank<3>>::value, "Not callable");
  57. static_assert(boost::hof::is_invocable<is_callable_rank_class, long, callable_rank<3>>::value, "Not callable");
  58. static_assert(boost::hof::is_invocable<is_callable_rank_class, double, callable_rank<3>>::value, "Not callable");
  59. static_assert(boost::hof::is_invocable<is_callable_rank_class, const int&, callable_rank<3>>::value, "Not callable");
  60. static_assert(boost::hof::is_invocable<is_callable_rank_class, const long&, callable_rank<3>>::value, "Not callable");
  61. static_assert(boost::hof::is_invocable<is_callable_rank_class, const double&, callable_rank<3>>::value, "Not callable");
  62. static_assert(boost::hof::is_invocable<is_callable_rank_class, int, callable_rank<4>>::value, "Not callable");
  63. static_assert(boost::hof::is_invocable<is_callable_rank_class, long, callable_rank<4>>::value, "Not callable");
  64. static_assert(boost::hof::is_invocable<is_callable_rank_class, double, callable_rank<4>>::value, "Not callable");
  65. static_assert(boost::hof::is_invocable<is_callable_rank_class, const int&, callable_rank<4>>::value, "Not callable");
  66. static_assert(boost::hof::is_invocable<is_callable_rank_class, const long&, callable_rank<4>>::value, "Not callable");
  67. static_assert(boost::hof::is_invocable<is_callable_rank_class, const double&, callable_rank<4>>::value, "Not callable");
  68. static_assert(boost::hof::is_invocable<is_callable_rank_class, int, callable_rank<5>>::value, "Not callable");
  69. static_assert(boost::hof::is_invocable<is_callable_rank_class, long, callable_rank<5>>::value, "Not callable");
  70. static_assert(boost::hof::is_invocable<is_callable_rank_class, double, callable_rank<5>>::value, "Not callable");
  71. static_assert(boost::hof::is_invocable<is_callable_rank_class, const int&, callable_rank<5>>::value, "Not callable");
  72. static_assert(boost::hof::is_invocable<is_callable_rank_class, const long&, callable_rank<5>>::value, "Not callable");
  73. static_assert(boost::hof::is_invocable<is_callable_rank_class, const double&, callable_rank<5>>::value, "Not callable");
  74. static_assert(boost::hof::is_invocable<is_callable_rank_class, int, callable_rank<6>>::value, "Not callable");
  75. static_assert(boost::hof::is_invocable<is_callable_rank_class, long, callable_rank<6>>::value, "Not callable");
  76. static_assert(boost::hof::is_invocable<is_callable_rank_class, double, callable_rank<6>>::value, "Not callable");
  77. static_assert(boost::hof::is_invocable<is_callable_rank_class, const int&, callable_rank<6>>::value, "Not callable");
  78. static_assert(boost::hof::is_invocable<is_callable_rank_class, const long&, callable_rank<6>>::value, "Not callable");
  79. static_assert(boost::hof::is_invocable<is_callable_rank_class, const double&, callable_rank<6>>::value, "Not callable");
  80. static_assert(not boost::hof::is_invocable<is_callable_rank_class, int, callable_rank<1>>::value, "callable failed");
  81. static_assert(not boost::hof::is_invocable<is_callable_rank_class, long, callable_rank<1>>::value, "callable failed");
  82. static_assert(not boost::hof::is_invocable<is_callable_rank_class, double, callable_rank<1>>::value, "callable failed");
  83. static_assert(not boost::hof::is_invocable<is_callable_rank_class, const int&, callable_rank<1>>::value, "callable failed");
  84. static_assert(not boost::hof::is_invocable<is_callable_rank_class, const long&, callable_rank<1>>::value, "callable failed");
  85. static_assert(not boost::hof::is_invocable<is_callable_rank_class, const double&, callable_rank<1>>::value, "callable failed");
  86. static_assert(not boost::hof::is_invocable<is_callable_rank_class, callable_test_param, callable_test_param>::value, "callable failed");
  87. static_assert(not boost::hof::is_invocable<is_callable_rank_class, callable_rank<3>, callable_test_param>::value, "callable failed");
  88. static_assert(not boost::hof::is_invocable<is_callable_rank_class, callable_rank<4>, callable_test_param>::value, "callable failed");
  89. static_assert(not boost::hof::is_invocable<is_callable_rank_class, callable_test_param, callable_rank<3>>::value, "callable failed");
  90. static_assert(not boost::hof::is_invocable<is_callable_rank_class, callable_test_param, callable_rank<4>>::value, "callable failed");
  91. static_assert(not boost::hof::is_invocable<is_callable_rank_class>::value, "callable failed");
  92. static_assert(not boost::hof::is_invocable<is_callable_rank_class, int, int>::value, "callable failed");
  93. };
  94. BOOST_HOF_STATIC_TEST_CASE()
  95. {
  96. typedef int(callable_rank<0>::*fn)(int);
  97. static_assert(boost::hof::is_invocable<fn, callable_rank<0>&, int>::value, "Failed");
  98. static_assert(boost::hof::is_invocable<fn, callable_rank<1>&, int>::value, "Failed");
  99. static_assert(!boost::hof::is_invocable<fn, callable_rank<0>&>::value, "Failed");
  100. static_assert(!boost::hof::is_invocable<fn, callable_rank<0> const&, int>::value, "Failed");
  101. };
  102. BOOST_HOF_STATIC_TEST_CASE()
  103. {
  104. typedef int(callable_rank<0>::*fn)(int);
  105. typedef callable_rank<0>* T;
  106. typedef callable_rank<1>* DT;
  107. typedef const callable_rank<0>* CT;
  108. typedef std::unique_ptr<callable_rank<0>> ST;
  109. static_assert(boost::hof::is_invocable<fn, T&, int>::value, "Failed");
  110. static_assert(boost::hof::is_invocable<fn, DT&, int>::value, "Failed");
  111. static_assert(boost::hof::is_invocable<fn, const T&, int>::value, "Failed");
  112. static_assert(boost::hof::is_invocable<fn, T&&, int>::value, "Failed");
  113. static_assert(boost::hof::is_invocable<fn, ST, int>::value, "Failed");
  114. static_assert(!boost::hof::is_invocable<fn, CT&, int>::value, "Failed");
  115. };
  116. BOOST_HOF_STATIC_TEST_CASE()
  117. {
  118. typedef int(callable_rank<0>::*fn);
  119. static_assert(!boost::hof::is_invocable<fn>::value, "Failed");
  120. };
  121. BOOST_HOF_STATIC_TEST_CASE()
  122. {
  123. typedef int(callable_rank<0>::*fn);
  124. static_assert(boost::hof::is_invocable<fn, callable_rank<0>&>::value, "Failed");
  125. static_assert(boost::hof::is_invocable<fn, callable_rank<0>&&>::value, "Failed");
  126. static_assert(boost::hof::is_invocable<fn, const callable_rank<0>&>::value, "Failed");
  127. static_assert(boost::hof::is_invocable<fn, callable_rank<1>&>::value, "Failed");
  128. };
  129. BOOST_HOF_STATIC_TEST_CASE()
  130. {
  131. typedef int(callable_rank<0>::*fn);
  132. typedef callable_rank<0>* T;
  133. typedef callable_rank<1>* DT;
  134. typedef const callable_rank<0>* CT;
  135. typedef std::unique_ptr<callable_rank<0>> ST;
  136. static_assert(boost::hof::is_invocable<fn, T&>::value, "Failed");
  137. static_assert(boost::hof::is_invocable<fn, DT&>::value, "Failed");
  138. static_assert(boost::hof::is_invocable<fn, const T&>::value, "Failed");
  139. static_assert(boost::hof::is_invocable<fn, T&&>::value, "Failed");
  140. static_assert(boost::hof::is_invocable<fn, ST>::value, "Failed");
  141. static_assert(boost::hof::is_invocable<fn, CT&>::value, "Failed");
  142. };
  143. BOOST_HOF_STATIC_TEST_CASE()
  144. {
  145. typedef void(*fp)(callable_rank<0>&, int);
  146. static_assert(boost::hof::is_invocable<fp, callable_rank<0>&, int>::value, "Failed");
  147. static_assert(boost::hof::is_invocable<fp, callable_rank<1>&, int>::value, "Failed");
  148. static_assert(!boost::hof::is_invocable<fp, const callable_rank<0>&, int>::value, "Failed");
  149. static_assert(!boost::hof::is_invocable<fp>::value, "Failed");
  150. static_assert(!boost::hof::is_invocable<fp, callable_rank<0>&>::value, "Failed");
  151. };
  152. BOOST_HOF_STATIC_TEST_CASE()
  153. {
  154. typedef void(&fp)(callable_rank<0>&, int);
  155. static_assert(boost::hof::is_invocable<fp, callable_rank<0>&, int>::value, "Failed");
  156. static_assert(boost::hof::is_invocable<fp, callable_rank<1>&, int>::value, "Failed");
  157. static_assert(!boost::hof::is_invocable<fp, const callable_rank<0>&, int>::value, "Failed");
  158. static_assert(!boost::hof::is_invocable<fp>::value, "Failed");
  159. static_assert(!boost::hof::is_invocable<fp, callable_rank<0>&>::value, "Failed");
  160. };