pointer_traits_element_type_test.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. template<class T>
  17. struct E1 {
  18. typedef bool element_type;
  19. };
  20. template<class T1, class T2>
  21. struct E2 {
  22. typedef bool element_type;
  23. };
  24. template<class T1, class T2, class T3>
  25. struct E3 {
  26. typedef bool element_type;
  27. };
  28. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  29. template<class T, class... U>
  30. struct P { };
  31. template<class T, class... U>
  32. struct E {
  33. typedef bool element_type;
  34. };
  35. #endif
  36. int main()
  37. {
  38. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int,
  39. boost::pointer_traits<int*>::element_type>));
  40. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int,
  41. boost::pointer_traits<P1<int> >::element_type>));
  42. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int,
  43. boost::pointer_traits<P2<int, char> >::element_type>));
  44. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int,
  45. boost::pointer_traits<P3<int, char, char> >::element_type>));
  46. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  47. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int,
  48. boost::pointer_traits<P<int, char, char, char> >::element_type>));
  49. #endif
  50. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool,
  51. boost::pointer_traits<E1<int> >::element_type>));
  52. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool,
  53. boost::pointer_traits<E2<int, int> >::element_type>));
  54. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool,
  55. boost::pointer_traits<E3<int, int, int> >::element_type>));
  56. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  57. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool,
  58. boost::pointer_traits<E<int, int, int, int> >::element_type>));
  59. #endif
  60. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<void,
  61. boost::pointer_traits<void*>::element_type>));
  62. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<void,
  63. boost::pointer_traits<P1<void> >::element_type>));
  64. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool,
  65. boost::pointer_traits<E1<void> >::element_type>));
  66. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<const int,
  67. boost::pointer_traits<const int*>::element_type>));
  68. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<const int,
  69. boost::pointer_traits<P1<const int> >::element_type>));
  70. BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool,
  71. boost::pointer_traits<E1<const int> >::element_type>));
  72. return boost::report_errors();
  73. }