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