combine_cxx03.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2014. 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_COMBINE_CXX03_HPP
  11. #define BOOST_RANGE_DETAIL_COMBINE_CXX03_HPP
  12. #ifndef BOOST_RANGE_MIN_COMBINE_ARGS
  13. #define BOOST_RANGE_MIN_COMBINE_ARGS 2
  14. #endif
  15. #ifndef BOOST_RANGE_MAX_COMBINE_ARGS
  16. #define BOOST_RANGE_MAX_COMBINE_ARGS 5
  17. #endif
  18. #include <boost/config.hpp>
  19. #include <boost/iterator/zip_iterator.hpp>
  20. #include <boost/preprocessor/arithmetic/dec.hpp>
  21. #include <boost/preprocessor/arithmetic/div.hpp>
  22. #include <boost/preprocessor/arithmetic/mul.hpp>
  23. #include <boost/preprocessor/control.hpp>
  24. #include <boost/preprocessor/control/while.hpp>
  25. #include <boost/preprocessor/facilities/empty.hpp>
  26. #include <boost/preprocessor/facilities/identity.hpp>
  27. #include <boost/preprocessor/iteration/local.hpp>
  28. #include <boost/preprocessor/punctuation/comma.hpp>
  29. #include <boost/preprocessor/repetition.hpp>
  30. #include <boost/preprocessor/tuple/elem.hpp>
  31. #include <boost/range/iterator_range_core.hpp>
  32. #include <boost/type_traits/remove_reference.hpp>
  33. #include <boost/mpl/transform.hpp>
  34. #include <boost/utility/result_of.hpp>
  35. #include <vector>
  36. #include <list>
  37. namespace boost
  38. {
  39. namespace range_detail
  40. {
  41. template<typename F, typename T, int SIZE>
  42. struct combined_result_impl;
  43. template<typename F, typename T>
  44. struct combined_result
  45. : combined_result_impl<F, T, tuples::length<T>::value>
  46. {
  47. };
  48. #define BOOST_RANGE_combined_element(z, n, data) \
  49. typename tuples::element<n, T>::type
  50. #define BOOST_RANGE_combined_result(z, n, data) \
  51. template<typename F, typename T> \
  52. struct combined_result_impl <F,T,n> \
  53. : result_of<F(BOOST_PP_ENUM(n, BOOST_RANGE_combined_element, ~))> \
  54. { \
  55. };
  56. #define BOOST_PP_LOCAL_MACRO(n) BOOST_RANGE_combined_result(~,n,~)
  57. #define BOOST_PP_LOCAL_LIMITS (BOOST_RANGE_MIN_COMBINE_ARGS, \
  58. BOOST_RANGE_MAX_COMBINE_ARGS)
  59. #include BOOST_PP_LOCAL_ITERATE()
  60. #define BOOST_RANGE_combined_get(z, n, data) get<n>(tuple)
  61. #define BOOST_RANGE_combined_unpack(z, n, data) \
  62. template<typename F, typename T> inline \
  63. typename combined_result<F,T>::type \
  64. unpack_(mpl::int_<n>, F f, const T& tuple) \
  65. { \
  66. return f(BOOST_PP_ENUM(n, BOOST_RANGE_combined_get, ~)); \
  67. }
  68. #define BOOST_PP_LOCAL_MACRO(n) BOOST_RANGE_combined_unpack(~,n,~)
  69. #define BOOST_PP_LOCAL_LIMITS (BOOST_RANGE_MIN_COMBINE_ARGS, \
  70. BOOST_RANGE_MAX_COMBINE_ARGS)
  71. #include BOOST_PP_LOCAL_ITERATE()
  72. } // namespace range_detail
  73. namespace range
  74. {
  75. #define BOOST_RANGE_combined_seq(z, n, data) boost::data(BOOST_PP_CAT(r,n))
  76. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  77. #include <boost/range/detail/combine_no_rvalue.hpp>
  78. #else // by using rvalue references we avoid requiring 2^n overloads.
  79. #include <boost/range/detail/combine_rvalue.hpp>
  80. #endif
  81. #define BOOST_PP_LOCAL_MACRO(n) BOOST_RANGE_combine(~,n,~)
  82. #define BOOST_PP_LOCAL_LIMITS (BOOST_RANGE_MIN_COMBINE_ARGS, \
  83. BOOST_RANGE_MAX_COMBINE_ARGS)
  84. #include BOOST_PP_LOCAL_ITERATE()
  85. } // namespace range
  86. using boost::range::combine;
  87. } // namespace boost
  88. #endif // include guard
  89. #undef BOOST_RANGE_combined_element
  90. #undef BOOST_RANGE_combined_result
  91. #undef BOOST_RANGE_combined_get
  92. #undef BOOST_RANGE_combined_unpack
  93. #undef BOOST_RANGE_combined_seq
  94. #undef BOOST_RANGE_combined_exp_pred
  95. #undef BOOST_RANGE_combined_exp_op
  96. #undef BOOST_RANGE_combined_exp
  97. #undef BOOST_RANGE_combined_bitset_pred
  98. #undef BOOST_RANGE_combined_bitset_op
  99. #undef BOOST_RANGE_combined_bitset
  100. #undef BOOST_RANGE_combined_range_iterator
  101. #undef BOOST_RANGE_combined_args
  102. #undef BOOST_RANGE_combine_impl
  103. #undef BOOST_RANGE_combine