common.hpp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Boost.Range library
  2. //
  3. // Copyright Thorsten Ottosen 2003-2004. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org/libs/range/
  9. //
  10. #ifndef BOOST_RANGE_DETAIL_COMMON_HPP
  11. #define BOOST_RANGE_DETAIL_COMMON_HPP
  12. #if defined(_MSC_VER)
  13. # pragma once
  14. #endif
  15. #include <boost/range/config.hpp>
  16. #include <boost/range/detail/sfinae.hpp>
  17. #include <boost/type_traits/is_void.hpp>
  18. #include <boost/mpl/if.hpp>
  19. #include <boost/mpl/int.hpp>
  20. #include <cstddef>
  21. //////////////////////////////////////////////////////////////////////////////
  22. // missing partial specialization workaround.
  23. //////////////////////////////////////////////////////////////////////////////
  24. namespace boost
  25. {
  26. namespace range_detail
  27. {
  28. // 1 = std containers
  29. // 2 = std::pair
  30. // 3 = const std::pair
  31. // 4 = array
  32. // 5 = const array
  33. // 6 = char array
  34. // 7 = wchar_t array
  35. // 8 = char*
  36. // 9 = const char*
  37. // 10 = whar_t*
  38. // 11 = const wchar_t*
  39. // 12 = string
  40. typedef mpl::int_<1>::type std_container_;
  41. typedef mpl::int_<2>::type std_pair_;
  42. typedef mpl::int_<3>::type const_std_pair_;
  43. typedef mpl::int_<4>::type array_;
  44. typedef mpl::int_<5>::type const_array_;
  45. typedef mpl::int_<6>::type char_array_;
  46. typedef mpl::int_<7>::type wchar_t_array_;
  47. typedef mpl::int_<8>::type char_ptr_;
  48. typedef mpl::int_<9>::type const_char_ptr_;
  49. typedef mpl::int_<10>::type wchar_t_ptr_;
  50. typedef mpl::int_<11>::type const_wchar_t_ptr_;
  51. typedef mpl::int_<12>::type string_;
  52. template< typename C >
  53. struct range_helper
  54. {
  55. static C* c;
  56. static C ptr;
  57. BOOST_STATIC_CONSTANT( bool, is_pair_ = sizeof( boost::range_detail::is_pair_impl( c ) ) == sizeof( yes_type ) );
  58. BOOST_STATIC_CONSTANT( bool, is_char_ptr_ = sizeof( boost::range_detail::is_char_ptr_impl( ptr ) ) == sizeof( yes_type ) );
  59. BOOST_STATIC_CONSTANT( bool, is_const_char_ptr_ = sizeof( boost::range_detail::is_const_char_ptr_impl( ptr ) ) == sizeof( yes_type ) );
  60. BOOST_STATIC_CONSTANT( bool, is_wchar_t_ptr_ = sizeof( boost::range_detail::is_wchar_t_ptr_impl( ptr ) ) == sizeof( yes_type ) );
  61. BOOST_STATIC_CONSTANT( bool, is_const_wchar_t_ptr_ = sizeof( boost::range_detail::is_const_wchar_t_ptr_impl( ptr ) ) == sizeof( yes_type ) );
  62. BOOST_STATIC_CONSTANT( bool, is_char_array_ = sizeof( boost::range_detail::is_char_array_impl( ptr ) ) == sizeof( yes_type ) );
  63. BOOST_STATIC_CONSTANT( bool, is_wchar_t_array_ = sizeof( boost::range_detail::is_wchar_t_array_impl( ptr ) ) == sizeof( yes_type ) );
  64. BOOST_STATIC_CONSTANT( bool, is_string_ = (is_const_char_ptr_ || is_const_wchar_t_ptr_));
  65. BOOST_STATIC_CONSTANT( bool, is_array_ = boost::is_array<C>::value );
  66. };
  67. template< typename C >
  68. class range
  69. {
  70. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_pair_,
  71. boost::range_detail::std_pair_,
  72. void >::type pair_t;
  73. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_array_,
  74. boost::range_detail::array_,
  75. pair_t >::type array_t;
  76. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_string_,
  77. boost::range_detail::string_,
  78. array_t >::type string_t;
  79. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_const_char_ptr_,
  80. boost::range_detail::const_char_ptr_,
  81. string_t >::type const_char_ptr_t;
  82. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_char_ptr_,
  83. boost::range_detail::char_ptr_,
  84. const_char_ptr_t >::type char_ptr_t;
  85. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_const_wchar_t_ptr_,
  86. boost::range_detail::const_wchar_t_ptr_,
  87. char_ptr_t >::type const_wchar_ptr_t;
  88. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_wchar_t_ptr_,
  89. boost::range_detail::wchar_t_ptr_,
  90. const_wchar_ptr_t >::type wchar_ptr_t;
  91. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_wchar_t_array_,
  92. boost::range_detail::wchar_t_array_,
  93. wchar_ptr_t >::type wchar_array_t;
  94. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_char_array_,
  95. boost::range_detail::char_array_,
  96. wchar_array_t >::type char_array_t;
  97. public:
  98. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::is_void<char_array_t>::value,
  99. boost::range_detail::std_container_,
  100. char_array_t >::type type;
  101. }; // class 'range'
  102. }
  103. }
  104. #endif