common.hpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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) && (_MSC_VER >= 1200)
  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/type_traits/detail/ice_or.hpp>
  19. #include <boost/mpl/if.hpp>
  20. #include <boost/mpl/int.hpp>
  21. #include <cstddef>
  22. //////////////////////////////////////////////////////////////////////////////
  23. // missing partial specialization workaround.
  24. //////////////////////////////////////////////////////////////////////////////
  25. namespace boost
  26. {
  27. namespace range_detail
  28. {
  29. // 1 = std containers
  30. // 2 = std::pair
  31. // 3 = const std::pair
  32. // 4 = array
  33. // 5 = const array
  34. // 6 = char array
  35. // 7 = wchar_t array
  36. // 8 = char*
  37. // 9 = const char*
  38. // 10 = whar_t*
  39. // 11 = const wchar_t*
  40. // 12 = string
  41. typedef mpl::int_<1>::type std_container_;
  42. typedef mpl::int_<2>::type std_pair_;
  43. typedef mpl::int_<3>::type const_std_pair_;
  44. typedef mpl::int_<4>::type array_;
  45. typedef mpl::int_<5>::type const_array_;
  46. typedef mpl::int_<6>::type char_array_;
  47. typedef mpl::int_<7>::type wchar_t_array_;
  48. typedef mpl::int_<8>::type char_ptr_;
  49. typedef mpl::int_<9>::type const_char_ptr_;
  50. typedef mpl::int_<10>::type wchar_t_ptr_;
  51. typedef mpl::int_<11>::type const_wchar_t_ptr_;
  52. typedef mpl::int_<12>::type string_;
  53. template< typename C >
  54. struct range_helper
  55. {
  56. static C* c;
  57. static C ptr;
  58. BOOST_STATIC_CONSTANT( bool, is_pair_ = sizeof( boost::range_detail::is_pair_impl( c ) ) == sizeof( yes_type ) );
  59. BOOST_STATIC_CONSTANT( bool, is_char_ptr_ = sizeof( boost::range_detail::is_char_ptr_impl( ptr ) ) == sizeof( yes_type ) );
  60. BOOST_STATIC_CONSTANT( bool, is_const_char_ptr_ = sizeof( boost::range_detail::is_const_char_ptr_impl( ptr ) ) == sizeof( yes_type ) );
  61. BOOST_STATIC_CONSTANT( bool, is_wchar_t_ptr_ = sizeof( boost::range_detail::is_wchar_t_ptr_impl( ptr ) ) == sizeof( yes_type ) );
  62. BOOST_STATIC_CONSTANT( bool, is_const_wchar_t_ptr_ = sizeof( boost::range_detail::is_const_wchar_t_ptr_impl( ptr ) ) == sizeof( yes_type ) );
  63. BOOST_STATIC_CONSTANT( bool, is_char_array_ = sizeof( boost::range_detail::is_char_array_impl( ptr ) ) == sizeof( yes_type ) );
  64. BOOST_STATIC_CONSTANT( bool, is_wchar_t_array_ = sizeof( boost::range_detail::is_wchar_t_array_impl( ptr ) ) == sizeof( yes_type ) );
  65. BOOST_STATIC_CONSTANT( bool, is_string_ = (boost::type_traits::ice_or<is_const_char_ptr_, is_const_wchar_t_ptr_>::value ));
  66. BOOST_STATIC_CONSTANT( bool, is_array_ = boost::is_array<C>::value );
  67. };
  68. template< typename C >
  69. class range
  70. {
  71. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_pair_,
  72. boost::range_detail::std_pair_,
  73. void >::type pair_t;
  74. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_array_,
  75. boost::range_detail::array_,
  76. pair_t >::type array_t;
  77. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_string_,
  78. boost::range_detail::string_,
  79. array_t >::type string_t;
  80. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_const_char_ptr_,
  81. boost::range_detail::const_char_ptr_,
  82. string_t >::type const_char_ptr_t;
  83. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_char_ptr_,
  84. boost::range_detail::char_ptr_,
  85. const_char_ptr_t >::type char_ptr_t;
  86. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_const_wchar_t_ptr_,
  87. boost::range_detail::const_wchar_t_ptr_,
  88. char_ptr_t >::type const_wchar_ptr_t;
  89. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_wchar_t_ptr_,
  90. boost::range_detail::wchar_t_ptr_,
  91. const_wchar_ptr_t >::type wchar_ptr_t;
  92. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_wchar_t_array_,
  93. boost::range_detail::wchar_t_array_,
  94. wchar_ptr_t >::type wchar_array_t;
  95. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::range_detail::range_helper<C>::is_char_array_,
  96. boost::range_detail::char_array_,
  97. wchar_array_t >::type char_array_t;
  98. public:
  99. typedef BOOST_RANGE_DEDUCED_TYPENAME boost::mpl::if_c< ::boost::is_void<char_array_t>::value,
  100. boost::range_detail::std_container_,
  101. char_array_t >::type type;
  102. }; // class 'range'
  103. }
  104. }
  105. #endif