Brian Silverman | 598d029 | 2018-08-04 23:56:47 -0700 | [diff] [blame^] | 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 | |
| 13 | #ifndef BOOST_RANGE_MIN_COMBINE_ARGS |
| 14 | #define BOOST_RANGE_MIN_COMBINE_ARGS 2 |
| 15 | #endif |
| 16 | |
| 17 | #ifndef BOOST_RANGE_MAX_COMBINE_ARGS |
| 18 | #define BOOST_RANGE_MAX_COMBINE_ARGS 5 |
| 19 | #endif |
| 20 | |
| 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> |
| 38 | |
| 39 | #include <vector> |
| 40 | #include <list> |
| 41 | |
| 42 | namespace boost |
| 43 | { |
| 44 | namespace range_detail |
| 45 | { |
| 46 | |
| 47 | template<typename F, typename T, int SIZE> |
| 48 | struct combined_result_impl; |
| 49 | |
| 50 | template<typename F, typename T> |
| 51 | struct combined_result |
| 52 | : combined_result_impl<F, T, tuples::length<T>::value> |
| 53 | { |
| 54 | }; |
| 55 | |
| 56 | #define BOOST_RANGE_combined_element(z, n, data) \ |
| 57 | typename tuples::element<n, T>::type |
| 58 | |
| 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, ~))> \ |
| 63 | { \ |
| 64 | }; |
| 65 | |
| 66 | #define BOOST_PP_LOCAL_MACRO(n) BOOST_RANGE_combined_result(~,n,~) |
| 67 | |
| 68 | #define BOOST_PP_LOCAL_LIMITS (BOOST_RANGE_MIN_COMBINE_ARGS, \ |
| 69 | BOOST_RANGE_MAX_COMBINE_ARGS) |
| 70 | #include BOOST_PP_LOCAL_ITERATE() |
| 71 | |
| 72 | #define BOOST_RANGE_combined_get(z, n, data) get<n>(tuple) |
| 73 | |
| 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) \ |
| 78 | { \ |
| 79 | return f(BOOST_PP_ENUM(n, BOOST_RANGE_combined_get, ~)); \ |
| 80 | } |
| 81 | |
| 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() |
| 86 | |
| 87 | } // namespace range_detail |
| 88 | |
| 89 | namespace range |
| 90 | { |
| 91 | |
| 92 | #define BOOST_RANGE_combined_seq(z, n, data) boost::data(BOOST_PP_CAT(r,n)) |
| 93 | |
| 94 | #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES |
| 95 | |
| 96 | #include <boost/range/detail/combine_no_rvalue.hpp> |
| 97 | |
| 98 | #else // by using rvalue references we avoid requiring 2^n overloads. |
| 99 | |
| 100 | #include <boost/range/detail/combine_rvalue.hpp> |
| 101 | |
| 102 | #endif |
| 103 | |
| 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() |
| 108 | |
| 109 | } // namespace range |
| 110 | |
| 111 | using boost::range::combine; |
| 112 | |
| 113 | } // namespace boost |
| 114 | |
| 115 | #endif // include guard |
| 116 | |
| 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 |