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)
8 // For more information, see http://www.boost.org/libs/range/
10 #ifndef BOOST_RANGE_DETAIL_COMBINE_CXX03_HPP
11 #define BOOST_RANGE_DETAIL_COMBINE_CXX03_HPP
13 #ifndef BOOST_RANGE_MIN_COMBINE_ARGS
14 #define BOOST_RANGE_MIN_COMBINE_ARGS 2
17 #ifndef BOOST_RANGE_MAX_COMBINE_ARGS
18 #define BOOST_RANGE_MAX_COMBINE_ARGS 5
21 #include <boost/config.hpp>
22 #include <boost/iterator/zip_iterator.hpp>
23 #include <boost/preprocessor/arithmetic/dec.hpp>
24 #include <boost/preprocessor/arithmetic/div.hpp>
25 #include <boost/preprocessor/arithmetic/mul.hpp>
26 #include <boost/preprocessor/control.hpp>
27 #include <boost/preprocessor/control/while.hpp>
28 #include <boost/preprocessor/facilities/empty.hpp>
29 #include <boost/preprocessor/facilities/identity.hpp>
30 #include <boost/preprocessor/iteration/local.hpp>
31 #include <boost/preprocessor/punctuation/comma.hpp>
32 #include <boost/preprocessor/repetition.hpp>
33 #include <boost/preprocessor/tuple/elem.hpp>
34 #include <boost/range/iterator_range_core.hpp>
35 #include <boost/type_traits/remove_reference.hpp>
36 #include <boost/mpl/transform.hpp>
37 #include <boost/utility/result_of.hpp>
44 namespace range_detail
47 template<typename F, typename T, int SIZE>
48 struct combined_result_impl;
50 template<typename F, typename T>
51 struct combined_result
52 : combined_result_impl<F, T, tuples::length<T>::value>
56 #define BOOST_RANGE_combined_element(z, n, data) \
57 typename tuples::element<n, T>::type
59 #define BOOST_RANGE_combined_result(z, n, data) \
60 template<typename F, typename T> \
61 struct combined_result_impl <F,T,n> \
62 : result_of<F(BOOST_PP_ENUM(n, BOOST_RANGE_combined_element, ~))> \
66 #define BOOST_PP_LOCAL_MACRO(n) BOOST_RANGE_combined_result(~,n,~)
68 #define BOOST_PP_LOCAL_LIMITS (BOOST_RANGE_MIN_COMBINE_ARGS, \
69 BOOST_RANGE_MAX_COMBINE_ARGS)
70 #include BOOST_PP_LOCAL_ITERATE()
72 #define BOOST_RANGE_combined_get(z, n, data) get<n>(tuple)
74 #define BOOST_RANGE_combined_unpack(z, n, data) \
75 template<typename F, typename T> inline \
76 typename combined_result<F,T>::type \
77 unpack_(mpl::int_<n>, F f, const T& tuple) \
79 return f(BOOST_PP_ENUM(n, BOOST_RANGE_combined_get, ~)); \
82 #define BOOST_PP_LOCAL_MACRO(n) BOOST_RANGE_combined_unpack(~,n,~)
83 #define BOOST_PP_LOCAL_LIMITS (BOOST_RANGE_MIN_COMBINE_ARGS, \
84 BOOST_RANGE_MAX_COMBINE_ARGS)
85 #include BOOST_PP_LOCAL_ITERATE()
87 } // namespace range_detail
92 #define BOOST_RANGE_combined_seq(z, n, data) boost::data(BOOST_PP_CAT(r,n))
94 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
96 #include <boost/range/detail/combine_no_rvalue.hpp>
98 #else // by using rvalue references we avoid requiring 2^n overloads.
100 #include <boost/range/detail/combine_rvalue.hpp>
104 #define BOOST_PP_LOCAL_MACRO(n) BOOST_RANGE_combine(~,n,~)
105 #define BOOST_PP_LOCAL_LIMITS (BOOST_RANGE_MIN_COMBINE_ARGS, \
106 BOOST_RANGE_MAX_COMBINE_ARGS)
107 #include BOOST_PP_LOCAL_ITERATE()
111 using boost::range::combine;
115 #endif // include guard
117 #undef BOOST_RANGE_combined_element
118 #undef BOOST_RANGE_combined_result
119 #undef BOOST_RANGE_combined_get
120 #undef BOOST_RANGE_combined_unpack
121 #undef BOOST_RANGE_combined_seq
122 #undef BOOST_RANGE_combined_exp_pred
123 #undef BOOST_RANGE_combined_exp_op
124 #undef BOOST_RANGE_combined_exp
125 #undef BOOST_RANGE_combined_bitset_pred
126 #undef BOOST_RANGE_combined_bitset_op
127 #undef BOOST_RANGE_combined_bitset
128 #undef BOOST_RANGE_combined_range_iterator
129 #undef BOOST_RANGE_combined_args
130 #undef BOOST_RANGE_combine_impl
131 #undef BOOST_RANGE_combine