[857] | 1 | /*=============================================================================
|
---|
| 2 | Copyright (c) 2003 Joel de Guzman
|
---|
| 3 |
|
---|
| 4 | Use, modification and distribution is subject to the Boost Software
|
---|
| 5 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
| 6 | http://www.boost.org/LICENSE_1_0.txt)
|
---|
| 7 | ==============================================================================*/
|
---|
| 8 | #if !defined(FUSION_SEQUENCE_DETAIL_GENERATE_HPP)
|
---|
| 9 | #define FUSION_SEQUENCE_DETAIL_GENERATE_HPP
|
---|
| 10 |
|
---|
| 11 | #include <boost/spirit/fusion/sequence/tuple.hpp>
|
---|
| 12 | #include <boost/spirit/fusion/iterator/value_of.hpp>
|
---|
| 13 | #include <boost/spirit/fusion/iterator/next.hpp>
|
---|
| 14 | #include <boost/spirit/fusion/iterator/equal_to.hpp>
|
---|
| 15 | #include <boost/preprocessor/repetition/repeat.hpp>
|
---|
| 16 | #include <boost/preprocessor/repetition/enum.hpp>
|
---|
| 17 | #include <boost/preprocessor/arithmetic/inc.hpp>
|
---|
| 18 | #include <boost/preprocessor/arithmetic/dec.hpp>
|
---|
| 19 | #include <boost/mpl/eval_if.hpp>
|
---|
| 20 | #include <boost/mpl/identity.hpp>
|
---|
| 21 |
|
---|
| 22 | #define FUSION_DEREF_ITERATOR(z, n, data) \
|
---|
| 23 | typename checked_deref_iterator< \
|
---|
| 24 | BOOST_PP_CAT(T, n), Last>::type
|
---|
| 25 |
|
---|
| 26 | #define FUSION_NEXT_ITERATOR(z, n, data) \
|
---|
| 27 | typedef typename checked_next_iterator< \
|
---|
| 28 | BOOST_PP_CAT(T, n), Last>::type \
|
---|
| 29 | BOOST_PP_CAT(T, BOOST_PP_INC(n));
|
---|
| 30 |
|
---|
| 31 | namespace boost { namespace fusion { namespace detail
|
---|
| 32 | {
|
---|
| 33 | template <typename First, typename Last>
|
---|
| 34 | struct checked_deref_iterator
|
---|
| 35 | {
|
---|
| 36 | typedef typename
|
---|
| 37 | mpl::eval_if<
|
---|
| 38 | meta::equal_to<First, Last>
|
---|
| 39 | , mpl::identity<void_t>
|
---|
| 40 | , meta::value_of<First>
|
---|
| 41 | >::type
|
---|
| 42 | type;
|
---|
| 43 | };
|
---|
| 44 |
|
---|
| 45 | template <typename First, typename Last>
|
---|
| 46 | struct checked_next_iterator
|
---|
| 47 | {
|
---|
| 48 | typedef typename
|
---|
| 49 | mpl::eval_if<
|
---|
| 50 | meta::equal_to<First, Last>
|
---|
| 51 | , mpl::identity<Last>
|
---|
| 52 | , meta::next<First>
|
---|
| 53 | >::type
|
---|
| 54 | type;
|
---|
| 55 | };
|
---|
| 56 |
|
---|
| 57 | template <typename First, typename Last>
|
---|
| 58 | struct result_of_generate
|
---|
| 59 | {
|
---|
| 60 | typedef First T0;
|
---|
| 61 | BOOST_PP_REPEAT(
|
---|
| 62 | BOOST_PP_DEC(FUSION_MAX_TUPLE_SIZE), FUSION_NEXT_ITERATOR, _)
|
---|
| 63 | typedef tuple<BOOST_PP_ENUM(FUSION_MAX_TUPLE_SIZE
|
---|
| 64 | , FUSION_DEREF_ITERATOR, _)> type;
|
---|
| 65 | };
|
---|
| 66 |
|
---|
| 67 | template <typename First, typename Last>
|
---|
| 68 | inline typename result_of_generate<First, Last>::type
|
---|
| 69 | generate(First const& first, Last const&)
|
---|
| 70 | {
|
---|
| 71 | typedef typename result_of_generate<First, Last>::type result;
|
---|
| 72 | return result(first);
|
---|
| 73 | }
|
---|
| 74 | }}}
|
---|
| 75 |
|
---|
| 76 | #undef FUSION_DEREF_ITERATOR
|
---|
| 77 | #undef FUSION_NEXT_ITERATOR
|
---|
| 78 | #endif
|
---|
| 79 |
|
---|
| 80 |
|
---|