1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #ifndef BOOST_PP_IS_ITERATING
8 #if !defined(BOOST_SPIRIT_AS_VARIANT_NOVEMBER_16_2007_0420PM)
9 #define BOOST_SPIRIT_AS_VARIANT_NOVEMBER_16_2007_0420PM
11 #include <boost/preprocessor/iterate.hpp>
12 #include <boost/preprocessor/repetition/enum_params.hpp>
13 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
14 #include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
15 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
16 #include <boost/variant/variant_fwd.hpp>
17 #include <boost/fusion/include/size.hpp>
18 #include <boost/fusion/include/begin.hpp>
19 #include <boost/fusion/include/next.hpp>
20 #include <boost/fusion/include/value_of.hpp>
21 #include <boost/mpl/fold.hpp>
22 #include <boost/mpl/vector.hpp>
23 #include <boost/mpl/push_back.hpp>
24 #include <boost/mpl/equal_to.hpp>
25 #include <boost/mpl/contains.hpp>
26 #include <boost/mpl/limits/list.hpp>
27 #include <boost/type_traits/is_same.hpp>
29 namespace boost { namespace spirit { namespace detail
32 struct as_variant_impl;
34 #if !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
37 struct as_variant_impl<0>
39 template <typename Iterator>
42 typedef variant<> type;
47 #define BOOST_FUSION_NEXT_ITERATOR(z, n, data) \
48 typedef typename fusion::result_of::next<BOOST_PP_CAT(I, n)>::type \
49 BOOST_PP_CAT(I, BOOST_PP_INC(n));
51 #define BOOST_FUSION_NEXT_CALL_ITERATOR(z, n, data) \
52 typename gen::BOOST_PP_CAT(I, BOOST_PP_INC(n)) \
53 BOOST_PP_CAT(i, BOOST_PP_INC(n)) = fusion::next(BOOST_PP_CAT(i, n));
55 #define BOOST_FUSION_VALUE_OF_ITERATOR(z, n, data) \
56 typedef typename fusion::result_of::value_of<BOOST_PP_CAT(I, n)>::type \
59 #define BOOST_PP_FILENAME_1 <boost/spirit/home/support/detail/as_variant.hpp>
61 #if !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
62 #define BOOST_PP_ITERATION_LIMITS (1, BOOST_MPL_LIMIT_LIST_SIZE)
64 #define BOOST_PP_ITERATION_LIMITS (1, BOOST_VARIANT_LIMIT_TYPES)
67 #include BOOST_PP_ITERATE()
69 #undef BOOST_FUSION_NEXT_ITERATOR
70 #undef BOOST_FUSION_NEXT_CALL_ITERATOR
71 #undef BOOST_FUSION_VALUE_OF_ITERATOR
73 template <typename Sequence>
76 // build a variant generator being able to generate a variant holding
77 // all of the types as given in the typelist
79 detail::as_variant_impl<fusion::result_of::size<Sequence>::value>
82 // use this generator to create the actual variant
83 typedef typename gen::template apply<
84 typename fusion::result_of::begin<Sequence>::type
91 #else // defined(BOOST_PP_IS_ITERATING)
92 ///////////////////////////////////////////////////////////////////////////////
94 // Preprocessor vertical repetition code
96 ///////////////////////////////////////////////////////////////////////////////
98 #define N BOOST_PP_ITERATION()
101 struct as_variant_impl<N>
103 template <typename I0>
106 BOOST_PP_REPEAT(N, BOOST_FUSION_NEXT_ITERATOR, _)
107 BOOST_PP_REPEAT(N, BOOST_FUSION_VALUE_OF_ITERATOR, _)
108 typedef variant<BOOST_PP_ENUM_PARAMS(N, T)> type;
113 #endif // defined(BOOST_PP_IS_ITERATING)