is_function_test.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // (C) Copyright John Maddock 2000.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #ifdef TEST_STD
  6. # include <type_traits>
  7. #else
  8. # include <boost/type_traits/is_function.hpp>
  9. #endif
  10. #include "test.hpp"
  11. #include "check_integral_constant.hpp"
  12. #if defined(BOOST_GCC) && (BOOST_GCC >= 70000)
  13. #pragma GCC diagnostic ignored "-Wnoexcept-type"
  14. #endif
  15. #ifdef BOOST_TT_HAS_ASCCURATE_IS_FUNCTION
  16. struct X
  17. {
  18. void f() {}
  19. void fc() const {}
  20. void fv() volatile {}
  21. void fcv() const volatile {}
  22. void noexcept_f()noexcept {}
  23. void ref_f()const& {}
  24. void rvalue_f() && {}
  25. };
  26. template< class C, class F > void test_cv_qual(F C::*)
  27. {
  28. BOOST_CHECK_INTEGRAL_CONSTANT(boost::is_function< F >::value, true);
  29. }
  30. #endif
  31. TT_TEST_BEGIN(is_function)
  32. typedef void foo0_t();
  33. typedef void foo1_t(int);
  34. typedef void foo2_t(int&, double);
  35. typedef void foo3_t(int&, bool, int, int);
  36. typedef void foo4_t(int, bool, int*, int[], int, int, int, int, int);
  37. #if __cpp_noexcept_function_type
  38. typedef int foo5_t(void)noexcept;
  39. typedef int foo6_t(double)noexcept(false);
  40. typedef int foo7_t(int, double)noexcept(true);
  41. #endif
  42. typedef double foo8_t(double...);
  43. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<foo0_t>::value, true);
  44. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<foo1_t>::value, true);
  45. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<foo2_t>::value, true);
  46. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<foo3_t>::value, true);
  47. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<foo4_t>::value, true);
  48. #if defined(__cpp_noexcept_function_type) && !defined(BOOST_TT_NO_NOEXCEPT_SEPARATE_TYPE)
  49. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<foo5_t>::value, true);
  50. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<foo6_t>::value, true);
  51. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<foo7_t>::value, true);
  52. #endif
  53. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<foo8_t>::value, true);
  54. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<void>::value, false);
  55. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<int>::value, false);
  56. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  57. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<int&>::value, false);
  58. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  59. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<int&&>::value, false);
  60. #endif
  61. #else
  62. std::cout <<
  63. "<note>is_function will fail with some types (references for example)"
  64. "if the compiler doesn't support partial specialisation of class templates."
  65. "These are *not* tested here</note>" << std::endl;
  66. #endif
  67. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<int*>::value, false);
  68. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<int[]>::value, false);
  69. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<test_abc1>::value, false);
  70. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<int (*)(int)>::value, false);
  71. #ifdef BOOST_TT_TEST_MS_FUNC_SIGS
  72. typedef void __stdcall sfoo0_t();
  73. typedef void __stdcall sfoo1_t(int);
  74. typedef void __stdcall sfoo2_t(int&, double);
  75. typedef void __stdcall sfoo3_t(int&, bool, int, int);
  76. typedef void __stdcall sfoo4_t(int, bool, int*, int[], int, int, int, int, int);
  77. typedef void __cdecl cfoo0_t();
  78. typedef void __cdecl cfoo1_t(int);
  79. typedef void __cdecl cfoo2_t(int&, double);
  80. typedef void __cdecl cfoo3_t(int&, bool, int, int);
  81. typedef void __cdecl cfoo4_t(int, bool, int*, int[], int, int, int, int, int);
  82. #ifndef __CLR_VER
  83. typedef void __fastcall ffoo0_t();
  84. typedef void __fastcall ffoo1_t(int);
  85. typedef void __fastcall ffoo2_t(int&, double);
  86. typedef void __fastcall ffoo3_t(int&, bool, int, int);
  87. typedef void __fastcall ffoo4_t(int, bool, int*, int[], int, int, int, int, int);
  88. #endif
  89. #if (_MSC_VER >= 1800) && !defined(__CLR_VER) && (defined(_M_IX86_FP) && (_M_IX86_FP >= 2) || defined(_M_X64))
  90. typedef void __vectorcall vfoo0_t();
  91. typedef void __vectorcall vfoo1_t(int);
  92. typedef void __vectorcall vfoo2_t(int&, double);
  93. typedef void __vectorcall vfoo3_t(int&, bool, int, int);
  94. typedef void __vectorcall vfoo4_t(int, bool, int*, int[], int, int, int, int, int);
  95. #endif
  96. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<sfoo0_t>::value, true);
  97. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<sfoo1_t>::value, true);
  98. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<sfoo2_t>::value, true);
  99. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<sfoo3_t>::value, true);
  100. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<sfoo4_t>::value, true);
  101. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<cfoo0_t>::value, true);
  102. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<cfoo1_t>::value, true);
  103. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<cfoo2_t>::value, true);
  104. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<cfoo3_t>::value, true);
  105. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<cfoo4_t>::value, true);
  106. #ifndef __CLR_VER
  107. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<ffoo0_t>::value, true);
  108. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<ffoo1_t>::value, true);
  109. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<ffoo2_t>::value, true);
  110. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<ffoo3_t>::value, true);
  111. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<ffoo4_t>::value, true);
  112. #endif
  113. #if (_MSC_VER >= 1800) && !defined(__CLR_VER) && (defined(_M_IX86_FP) && (_M_IX86_FP >= 2) || defined(_M_X64))
  114. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<vfoo0_t>::value, true);
  115. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<vfoo1_t>::value, true);
  116. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<vfoo2_t>::value, true);
  117. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<vfoo3_t>::value, true);
  118. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_function<vfoo4_t>::value, true);
  119. #endif
  120. #endif
  121. #ifdef BOOST_TT_HAS_ASCCURATE_IS_FUNCTION
  122. test_cv_qual(&X::f);
  123. test_cv_qual(&X::fc);
  124. test_cv_qual(&X::fv);
  125. test_cv_qual(&X::fcv);
  126. #ifndef BOOST_TT_NO_NOEXCEPT_SEPARATE_TYPE
  127. test_cv_qual(&X::noexcept_f);
  128. #endif
  129. test_cv_qual(&X::ref_f);
  130. test_cv_qual(&X::rvalue_f);
  131. #endif
  132. TT_TEST_END