function_type.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <boost/callable_traits/function_type.hpp>
  2. #include "test.hpp"
  3. int main() {
  4. struct foo;
  5. {
  6. auto g = [](int, char){};
  7. using G = decltype(g);
  8. using F = void(int, char);
  9. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  10. CT_ASSERT(std::is_same<function_type_t<G const &>, F>::value);
  11. CT_ASSERT(std::is_same<function_type_t<G const &&>, F>::value);
  12. CT_ASSERT(std::is_same<function_type_t<G volatile &>, F>::value);
  13. CT_ASSERT(std::is_same<function_type_t<G &>, F>::value);
  14. CT_ASSERT(std::is_same<function_type_t<G &&>, F>::value);
  15. CT_ASSERT(std::is_same<function_type_t<
  16. decltype(&G::operator())>, void(G const &, int, char)>::value);
  17. }
  18. #ifndef BOOST_CLBL_TRTS_DISABLE_ABOMINABLE_FUNCTIONS
  19. {
  20. using G = void (int, char, ...) const LREF;
  21. using F = void (int, char, ...);
  22. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  23. }
  24. #endif
  25. {
  26. using G = void (*)(int, char) BOOST_CLBL_TRTS_TRANSACTION_SAFE_SPECIFIER;
  27. using F = void (int, char);
  28. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  29. }{
  30. using G = void (* const &)(int, char);
  31. using F = void (int, char);
  32. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  33. }{
  34. using G = int (* &&)();
  35. using F = int ();
  36. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  37. }{
  38. using G = int (* &&)();
  39. using F = int ();
  40. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  41. }{
  42. using G = char const * const & (&)(...);
  43. using F = char const * const & (...);
  44. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  45. }{
  46. struct G { int operator() (...) volatile; };
  47. using F = int (...);
  48. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  49. }{
  50. struct G { int operator() (...) volatile BOOST_CLBL_TRTS_NOEXCEPT_SPECIFIER; };
  51. using F = int (...);
  52. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  53. }{
  54. struct G { int operator() (...) const BOOST_CLBL_TRTS_NOEXCEPT_SPECIFIER; };
  55. using F = int (...);
  56. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  57. }{
  58. using G = void (foo::* const &)(int, int, int) LREF BOOST_CLBL_TRTS_TRANSACTION_SAFE_SPECIFIER;
  59. using F = void (foo &, int, int, int);
  60. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  61. }
  62. #ifndef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS
  63. {
  64. using G = void (foo::* const &)(int, int, int) RREF;
  65. using F = void (foo &&, int, int, int);
  66. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  67. }
  68. #endif
  69. {
  70. using G = void (foo::*)(int, int, int) const BOOST_CLBL_TRTS_TRANSACTION_SAFE_SPECIFIER;
  71. using F = void (foo const &, int, int, int);
  72. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  73. }{
  74. using G = void (foo::*)(int, int, int);
  75. using F = void (foo &, int, int, int);
  76. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  77. }{
  78. using G = void (foo::*)() BOOST_CLBL_TRTS_NOEXCEPT_SPECIFIER;
  79. using F = void (foo &);
  80. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  81. }{
  82. using G = void (foo::*)(int, int, int) const BOOST_CLBL_TRTS_NOEXCEPT_SPECIFIER;
  83. using F = void (foo const &, int, int, int);
  84. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  85. }{
  86. using G = void (foo::*)(int, int, int, ...) const BOOST_CLBL_TRTS_NOEXCEPT_SPECIFIER;
  87. using F = void (foo const &, int, int, int, ...);
  88. CT_ASSERT(std::is_same<TRAIT(function_type, G), F>::value);
  89. }
  90. }