combine_no_rvalue.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #define BOOST_RANGE_combined_exp_pred(d, data) BOOST_PP_TUPLE_ELEM(3, 0, data)
  11. #define BOOST_RANGE_combined_exp_op(d, data) \
  12. ( \
  13. BOOST_PP_DEC( \
  14. BOOST_PP_TUPLE_ELEM(3, 0, data) \
  15. ), \
  16. BOOST_PP_TUPLE_ELEM(3, 1, data), \
  17. BOOST_PP_MUL_D( \
  18. d, \
  19. BOOST_PP_TUPLE_ELEM(3, 2, data), \
  20. BOOST_PP_TUPLE_ELEM(3, 1, data) \
  21. ) \
  22. )
  23. #define BOOST_RANGE_combined_exp(x, n) \
  24. BOOST_PP_TUPLE_ELEM(3, 2, \
  25. BOOST_PP_WHILE(BOOST_RANGE_combined_exp_pred, \
  26. BOOST_RANGE_combined_exp_op, (n, x, 1)))
  27. #define BOOST_RANGE_combined_bitset_pred(n, state) \
  28. BOOST_PP_TUPLE_ELEM(2,1,state)
  29. #define BOOST_RANGE_combined_bitset_op(d, state) \
  30. (BOOST_PP_DIV_D(d, BOOST_PP_TUPLE_ELEM(2,0,state), 2), \
  31. BOOST_PP_DEC(BOOST_PP_TUPLE_ELEM(2,1,state)))
  32. #define BOOST_RANGE_combined_bitset(i, n) \
  33. BOOST_PP_MOD(BOOST_PP_TUPLE_ELEM(2, 0, \
  34. BOOST_PP_WHILE(BOOST_RANGE_combined_bitset_pred, \
  35. BOOST_RANGE_combined_bitset_op, (i,n))), 2)
  36. #define BOOST_RANGE_combined_range_iterator(z, n, i) \
  37. typename range_iterator< \
  38. BOOST_PP_CAT(R,n) \
  39. BOOST_PP_IF( \
  40. BOOST_RANGE_combined_bitset(i,n), \
  41. BOOST_PP_IDENTITY(const), \
  42. BOOST_PP_EMPTY)() \
  43. >::type
  44. #define BOOST_RANGE_combined_args(z, n, i) \
  45. BOOST_PP_CAT(R, n) \
  46. BOOST_PP_IF(BOOST_RANGE_combined_bitset(i,n), const&, &) \
  47. BOOST_PP_CAT(r, n)
  48. #define BOOST_RANGE_combine_impl(z, i, n)\
  49. template<BOOST_PP_ENUM_PARAMS(n, typename R)> \
  50. inline range::combined_range< \
  51. boost::tuple<BOOST_PP_ENUM(n, BOOST_RANGE_combined_range_iterator, i)> \
  52. > \
  53. combine(BOOST_PP_ENUM(n, BOOST_RANGE_combined_args, i)) \
  54. { \
  55. typedef tuple< \
  56. BOOST_PP_ENUM(n, BOOST_RANGE_combined_range_iterator, i) \
  57. > rng_tuple_t; \
  58. return range::combined_range<rng_tuple_t>( \
  59. rng_tuple_t(BOOST_PP_ENUM(n, BOOST_RANGE_combined_seq, begin)), \
  60. rng_tuple_t(BOOST_PP_ENUM(n, BOOST_RANGE_combined_seq, end))); \
  61. }
  62. #define BOOST_RANGE_combine(z, n, data) \
  63. BOOST_PP_REPEAT(BOOST_RANGE_combined_exp(2,n), BOOST_RANGE_combine_impl, n)