pointer_traits_rebind_test.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. Copyright 2017 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <boost/core/pointer_traits.hpp>
  8. #include <boost/core/is_same.hpp>
  9. #include <boost/core/lightweight_test_trait.hpp>
  10. template<class T>
  11. struct P1 { };
  12. template<class T1, class T2>
  13. struct P2 { };
  14. template<class T1, class T2, class T3>
  15. struct P3 { };
  16. #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  17. template<class T>
  18. struct E1 {
  19. template<class U>
  20. using rebind = E1<bool>;
  21. };
  22. template<class T1, class T2>
  23. struct E2 {
  24. template<class U>
  25. using rebind = E2<bool, T2>;
  26. };
  27. template<class T1, class T2, class T3>
  28. struct E3 {
  29. template<class U>
  30. using rebind = E3<bool, T2, T3>;
  31. };
  32. #endif
  33. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  34. template<class T, class... U>
  35. struct P { };
  36. #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  37. template<class T, class... U>
  38. struct E {
  39. template<class V>
  40. using rebind = E<bool, U...>;
  41. };
  42. #endif
  43. #endif
  44. struct R { };
  45. int main()
  46. {
  47. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<char*,
  48. boost::pointer_traits<R*>::rebind_to<char>::type>));
  49. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P1<char>,
  50. boost::pointer_traits<P1<R> >::rebind_to<char>::type>));
  51. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P2<char, R>,
  52. boost::pointer_traits<P2<R, R> >::rebind_to<char>::type>));
  53. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P3<char, R, R>,
  54. boost::pointer_traits<P3<R, R, R> >::rebind_to<char>::type>));
  55. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  56. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P<char, R, R, R>,
  57. boost::pointer_traits<P<R, R, R, R> >::rebind_to<char>::type>));
  58. #endif
  59. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<void*,
  60. boost::pointer_traits<R*>::rebind_to<void>::type>));
  61. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P1<void>,
  62. boost::pointer_traits<P1<R> >::rebind_to<void>::type>));
  63. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<R*,
  64. boost::pointer_traits<void*>::rebind_to<R>::type>));
  65. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P1<R>,
  66. boost::pointer_traits<P1<void> >::rebind_to<R>::type>));
  67. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<const int*,
  68. boost::pointer_traits<R*>::rebind_to<const int>::type>));
  69. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P1<const int>,
  70. boost::pointer_traits<P1<R> >::rebind_to<const int>::type>));
  71. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int*,
  72. boost::pointer_traits<const R*>::rebind_to<int>::type>));
  73. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P1<int>,
  74. boost::pointer_traits<P1<const R> >::rebind_to<int>::type>));
  75. #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  76. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E1<bool>,
  77. boost::pointer_traits<E1<R> >::rebind_to<char>::type>));
  78. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E2<bool, R>,
  79. boost::pointer_traits<E2<R, R> >::rebind_to<char>::type>));
  80. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E3<bool, R, R>,
  81. boost::pointer_traits<E3<R, R, R> >::rebind_to<char>::type>));
  82. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  83. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E<bool, R, R, R>,
  84. boost::pointer_traits<E<R, R, R, R> >::rebind_to<char>::type>));
  85. #endif
  86. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E1<bool>,
  87. boost::pointer_traits<E1<R> >::rebind_to<void>::type>));
  88. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E1<bool>,
  89. boost::pointer_traits<E1<void> >::rebind_to<R>::type>));
  90. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E1<bool>,
  91. boost::pointer_traits<E1<R> >::rebind_to<const int>::type>));
  92. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E1<bool>,
  93. boost::pointer_traits<E1<const R> >::rebind_to<int>::type>));
  94. #endif
  95. return boost::report_errors();
  96. }