source: NonGTP/Boost/boost/spirit/fusion/sequence/detail/tuple_builder.hpp @ 857

Revision 857, 3.2 KB checked in by igarcia, 19 years ago (diff)
Line 
1/*=============================================================================
2    Copyright (c) 2001-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_TUPLE_BUILDER_HPP)
9#define FUSION_SEQUENCE_DETAIL_TUPLE_BUILDER_HPP
10
11#include <boost/spirit/fusion/detail/config.hpp>
12#include <boost/spirit/fusion/sequence/limits.hpp>
13
14//  include tuple0..N where N is FUSION_MAX_TUPLE_SIZE
15#include <boost/spirit/fusion/sequence/tuple10.hpp>
16#if (FUSION_MAX_TUPLE_SIZE > 10)
17#include <boost/spirit/fusion/sequence/tuple20.hpp>
18#endif
19#if (FUSION_MAX_TUPLE_SIZE > 20)
20#include <boost/spirit/fusion/sequence/tuple30.hpp>
21#endif
22#if (FUSION_MAX_TUPLE_SIZE > 30)
23#include <boost/spirit/fusion/sequence/tuple40.hpp>
24#endif
25#if (FUSION_MAX_TUPLE_SIZE > 40)
26#include <boost/spirit/fusion/sequence/tuple50.hpp>
27#endif
28
29#include <boost/mpl/not.hpp>
30#include <boost/mpl/distance.hpp>
31#include <boost/mpl/find.hpp>
32#include <boost/mpl/begin_end.hpp>
33#include <boost/preprocessor/cat.hpp>
34#include <boost/preprocessor/repetition/enum_params.hpp>
35#include <boost/preprocessor/repetition/repeat_from_to.hpp>
36
37namespace boost { namespace fusion
38{
39    struct void_t;
40}}
41
42namespace boost { namespace fusion { namespace detail
43{
44    template <int N>
45    struct get_tuple_n;
46
47    template <>
48    struct get_tuple_n<0>
49    {
50        template <BOOST_PP_ENUM_PARAMS(FUSION_MAX_TUPLE_SIZE, typename T)>
51        struct call
52        {
53            typedef tuple0 type;
54        };
55    };
56
57#define FUSION_GET_TUPLE_N(z, n, _)                                             \
58    template <>                                                                 \
59    struct get_tuple_n<n>                                                       \
60    {                                                                           \
61        template <BOOST_PP_ENUM_PARAMS(FUSION_MAX_TUPLE_SIZE, typename T)>      \
62        struct call                                                             \
63        {                                                                       \
64            typedef BOOST_PP_CAT(tuple, n)<BOOST_PP_ENUM_PARAMS(n, T)> type;    \
65        };                                                                      \
66    };
67
68    BOOST_PP_REPEAT_FROM_TO(1, FUSION_MAX_TUPLE_SIZE, FUSION_GET_TUPLE_N, _)
69#undef FUSION_GET_TUPLE_N
70
71    template <BOOST_PP_ENUM_PARAMS(FUSION_MAX_TUPLE_SIZE, typename T)>
72    struct tuple_builder
73    {
74        typedef
75            mpl::BOOST_PP_CAT(vector, FUSION_MAX_TUPLE_SIZE)
76                <BOOST_PP_ENUM_PARAMS(FUSION_MAX_TUPLE_SIZE, T)>
77        input;
78
79        typedef typename mpl::begin<input>::type begin;
80        typedef typename mpl::find<input, void_t>::type end;
81        typedef typename mpl::distance<begin, end>::type size;
82
83        typedef typename get_tuple_n<FUSION_GET_VALUE(size)>::template
84            call<BOOST_PP_ENUM_PARAMS(FUSION_MAX_TUPLE_SIZE, T)>::type
85        type;
86    };
87}}}
88
89#endif
Note: See TracBrowser for help on using the repository browser.