tricky_partial_spec_test.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/alignment_of.hpp>
  9. #include <boost/type_traits/has_nothrow_assign.hpp>
  10. #include <boost/type_traits/has_nothrow_constructor.hpp>
  11. #include <boost/type_traits/has_nothrow_copy.hpp>
  12. #include <boost/type_traits/is_base_and_derived.hpp>
  13. #include <boost/type_traits/is_base_of.hpp>
  14. #include <boost/type_traits/is_same.hpp>
  15. #include <boost/type_traits/is_convertible.hpp>
  16. #include <boost/type_traits/is_polymorphic.hpp>
  17. #include <boost/type_traits/is_member_pointer.hpp>
  18. #include <boost/type_traits/is_member_object_pointer.hpp>
  19. #include <boost/type_traits/is_member_function_pointer.hpp>
  20. #include <boost/type_traits/is_pointer.hpp>
  21. #endif
  22. #include "test.hpp"
  23. #include "check_integral_constant.hpp"
  24. #include <stdexcept>
  25. #include <new>
  26. #include <exception>
  27. //
  28. // VC++ emits an awful lot of warnings unless we define these:
  29. #ifdef BOOST_MSVC
  30. # pragma warning(disable:4244)
  31. #endif
  32. template <class T>
  33. struct align_calc
  34. {
  35. char padding;
  36. T instance;
  37. static std::ptrdiff_t get()
  38. {
  39. static align_calc<T> a;
  40. return reinterpret_cast<const char*>(&(a.instance)) - reinterpret_cast<const char*>(&(a.padding));
  41. }
  42. };
  43. #define ALIGNOF(x) align_calc<x>::get()
  44. TT_TEST_BEGIN(tricky_partial_specialization_test)
  45. //
  46. // corner cases which don't compile without partial specialization
  47. // support:
  48. //
  49. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<char&>::value, ALIGNOF(void*));
  50. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<char (&)(int)>::value, ALIGNOF(void*));
  51. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::alignment_of<char(&)[4]>::value, ALIGNOF(void*));
  52. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&,Derived>::value), false);
  53. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&,Derived&>::value), false);
  54. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,Derived&>::value), false);
  55. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,void>::value), false);
  56. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  57. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&&,Derived>::value), false);
  58. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base&&,Derived&&>::value), false);
  59. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_base_of<Base,Derived&&>::value), false);
  60. #endif
  61. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<void, int>::value), false);
  62. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<void, void>::value), true);
  63. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<void, const void>::value), false);
  64. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<test_abc1, test_abc1>::value), true);
  65. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same<test_abc1, const test_abc1>::value), false);
  66. BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_convertible<void,float>::value), false);
  67. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const UDT>::value, false);
  68. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<volatile empty_UDT>::value, false);
  69. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const VB>::value, true);
  70. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const volatile VD>::value, true);
  71. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const test_abc1>::value, true);
  72. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<volatile test_abc2>::value, true);
  73. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::exception>::value, true);
  74. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::bad_alloc>::value, true);
  75. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::runtime_error>::value, true);
  76. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::out_of_range>::value, true);
  77. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_polymorphic<const std::range_error>::value, true);
  78. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pointer<const f1>::value, true);
  79. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pointer<volatile f1>::value, true);
  80. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_pointer<const volatile f1>::value, true);
  81. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const f1>::value, false);
  82. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const mp>::value, true);
  83. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<volatile mp>::value, true);
  84. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const volatile mp>::value, true);
  85. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const mf3>::value, true);
  86. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<volatile mf3>::value, true);
  87. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_pointer<const volatile mf3>::value, true);
  88. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const f1>::value, false);
  89. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const mp>::value, true);
  90. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<volatile mp>::value, true);
  91. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const volatile mp>::value, true);
  92. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const mf3>::value, false);
  93. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<volatile mf3>::value, false);
  94. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_object_pointer<const volatile mf3>::value, false);
  95. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const f1>::value, false);
  96. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const mp>::value, false);
  97. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<volatile mp>::value, false);
  98. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const volatile mp>::value, false);
  99. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const mf3>::value, true);
  100. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<volatile mf3>::value, true);
  101. BOOST_CHECK_INTEGRAL_CONSTANT(::tt::is_member_function_pointer<const volatile mf3>::value, true);
  102. TT_TEST_END