indirect_traits_test.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright David Abrahams 2004. Distributed under the Boost
  2. // Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. //#include <stdio.h>
  5. #define BOOST_ENABLE_ASSERT_HANDLER
  6. #include <boost/assert.hpp>
  7. #include <boost/mpl/assert.hpp>
  8. #include <boost/python/detail/indirect_traits.hpp>
  9. #include <boost/mpl/assert.hpp>
  10. //#define print(expr) printf("%s ==> %s\n", #expr, expr)
  11. // not all the compilers can handle an incomplete class type here.
  12. struct X {};
  13. using namespace boost::python::indirect_traits;
  14. typedef void (X::*pmf)();
  15. BOOST_MPL_ASSERT((is_reference_to_function<int (&)()>));
  16. BOOST_MPL_ASSERT_NOT((is_reference_to_function<int (*)()>));
  17. BOOST_MPL_ASSERT_NOT((is_reference_to_function<int&>));
  18. BOOST_MPL_ASSERT_NOT((is_reference_to_function<pmf>));
  19. BOOST_MPL_ASSERT_NOT((is_pointer_to_function<int (&)()>));
  20. BOOST_MPL_ASSERT((is_pointer_to_function<int (*)()>));
  21. BOOST_MPL_ASSERT_NOT((is_pointer_to_function<int (*&)()>));
  22. BOOST_MPL_ASSERT_NOT((is_pointer_to_function<int (*const&)()>));
  23. BOOST_MPL_ASSERT_NOT((is_pointer_to_function<pmf>));
  24. BOOST_MPL_ASSERT_NOT((is_reference_to_function_pointer<int (&)()>));
  25. BOOST_MPL_ASSERT_NOT((is_reference_to_function_pointer<int (*)()>));
  26. BOOST_MPL_ASSERT_NOT((is_reference_to_function_pointer<int&>));
  27. BOOST_MPL_ASSERT((is_reference_to_function_pointer<int (*&)()>));
  28. BOOST_MPL_ASSERT((is_reference_to_function_pointer<int (*const&)()>));
  29. BOOST_MPL_ASSERT_NOT((is_reference_to_function_pointer<pmf>));
  30. BOOST_MPL_ASSERT((is_reference_to_pointer<int*&>));
  31. BOOST_MPL_ASSERT((is_reference_to_pointer<int* const&>));
  32. BOOST_MPL_ASSERT((is_reference_to_pointer<int*volatile&>));
  33. BOOST_MPL_ASSERT((is_reference_to_pointer<int*const volatile&>));
  34. BOOST_MPL_ASSERT((is_reference_to_pointer<int const*&>));
  35. BOOST_MPL_ASSERT((is_reference_to_pointer<int const* const&>));
  36. BOOST_MPL_ASSERT((is_reference_to_pointer<int const*volatile&>));
  37. BOOST_MPL_ASSERT((is_reference_to_pointer<int const*const volatile&>));
  38. BOOST_MPL_ASSERT_NOT((is_reference_to_pointer<pmf>));
  39. BOOST_MPL_ASSERT_NOT((is_reference_to_pointer<int const volatile>));
  40. BOOST_MPL_ASSERT_NOT((is_reference_to_pointer<int>));
  41. BOOST_MPL_ASSERT_NOT((is_reference_to_pointer<int*>));
  42. BOOST_MPL_ASSERT_NOT((is_reference_to_const<int*&>));
  43. BOOST_MPL_ASSERT((is_reference_to_const<int* const&>));
  44. BOOST_MPL_ASSERT_NOT((is_reference_to_const<int*volatile&>));
  45. BOOST_MPL_ASSERT((is_reference_to_const<int*const volatile&>));
  46. BOOST_MPL_ASSERT_NOT((is_reference_to_const<int const volatile>));
  47. BOOST_MPL_ASSERT_NOT((is_reference_to_const<int>));
  48. BOOST_MPL_ASSERT_NOT((is_reference_to_const<int*>));
  49. BOOST_MPL_ASSERT((is_reference_to_non_const<int*&>));
  50. BOOST_MPL_ASSERT_NOT((is_reference_to_non_const<int* const&>));
  51. BOOST_MPL_ASSERT((is_reference_to_non_const<int*volatile&>));
  52. BOOST_MPL_ASSERT_NOT((is_reference_to_non_const<int*const volatile&>));
  53. BOOST_MPL_ASSERT_NOT((is_reference_to_non_const<int const volatile>));
  54. BOOST_MPL_ASSERT_NOT((is_reference_to_non_const<int>));
  55. BOOST_MPL_ASSERT_NOT((is_reference_to_non_const<int*>));
  56. BOOST_MPL_ASSERT_NOT((is_reference_to_volatile<int*&>));
  57. BOOST_MPL_ASSERT_NOT((is_reference_to_volatile<int* const&>));
  58. BOOST_MPL_ASSERT((is_reference_to_volatile<int*volatile&>));
  59. BOOST_MPL_ASSERT((is_reference_to_volatile<int*const volatile&>));
  60. BOOST_MPL_ASSERT_NOT((is_reference_to_volatile<int const volatile>));
  61. BOOST_MPL_ASSERT_NOT((is_reference_to_volatile<int>));
  62. BOOST_MPL_ASSERT_NOT((is_reference_to_volatile<int*>));
  63. namespace tt = boost::python::indirect_traits;
  64. BOOST_MPL_ASSERT_NOT((tt::is_reference_to_class<int>));
  65. BOOST_MPL_ASSERT_NOT((tt::is_reference_to_class<int&>));
  66. BOOST_MPL_ASSERT_NOT((tt::is_reference_to_class<int*>));
  67. BOOST_MPL_ASSERT_NOT((tt::is_reference_to_class<pmf>));
  68. BOOST_MPL_ASSERT_NOT((tt::is_reference_to_class<pmf const&>));
  69. BOOST_MPL_ASSERT_NOT((tt::is_reference_to_class<X>));
  70. BOOST_MPL_ASSERT((tt::is_reference_to_class<X&>));
  71. BOOST_MPL_ASSERT((tt::is_reference_to_class<X const&>));
  72. BOOST_MPL_ASSERT((tt::is_reference_to_class<X volatile&>));
  73. BOOST_MPL_ASSERT((tt::is_reference_to_class<X const volatile&>));
  74. BOOST_MPL_ASSERT_NOT((is_pointer_to_class<int>));
  75. BOOST_MPL_ASSERT_NOT((is_pointer_to_class<int*>));
  76. BOOST_MPL_ASSERT_NOT((is_pointer_to_class<int&>));
  77. BOOST_MPL_ASSERT_NOT((is_pointer_to_class<X>));
  78. BOOST_MPL_ASSERT_NOT((is_pointer_to_class<X&>));
  79. BOOST_MPL_ASSERT_NOT((is_pointer_to_class<pmf>));
  80. BOOST_MPL_ASSERT_NOT((is_pointer_to_class<pmf const>));
  81. BOOST_MPL_ASSERT((is_pointer_to_class<X*>));
  82. BOOST_MPL_ASSERT((is_pointer_to_class<X const*>));
  83. BOOST_MPL_ASSERT((is_pointer_to_class<X volatile*>));
  84. BOOST_MPL_ASSERT((is_pointer_to_class<X const volatile*>));
  85. BOOST_MPL_ASSERT((tt::is_reference_to_member_function_pointer<pmf&>));
  86. BOOST_MPL_ASSERT((tt::is_reference_to_member_function_pointer<pmf const&>));
  87. BOOST_MPL_ASSERT((tt::is_reference_to_member_function_pointer<pmf volatile&>));
  88. BOOST_MPL_ASSERT((tt::is_reference_to_member_function_pointer<pmf const volatile&>));
  89. BOOST_MPL_ASSERT_NOT((tt::is_reference_to_member_function_pointer<pmf[2]>));
  90. BOOST_MPL_ASSERT_NOT((tt::is_reference_to_member_function_pointer<pmf(&)[2]>));
  91. BOOST_MPL_ASSERT_NOT((tt::is_reference_to_member_function_pointer<pmf>));