1 //-----------------------------------------------------------------------------
2 // boost variant/recursive_variant.hpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #ifndef BOOST_VARIANT_RECURSIVE_VARIANT_HPP
14 #define BOOST_VARIANT_RECURSIVE_VARIANT_HPP
16 #include "boost/variant/variant_fwd.hpp"
17 #include "boost/variant/detail/enable_recursive.hpp"
18 #include "boost/variant/detail/substitute_fwd.hpp"
19 #include "boost/variant/detail/make_variant_list.hpp"
20 #include "boost/variant/detail/over_sequence.hpp"
22 #include "boost/mpl/aux_/lambda_arity_param.hpp"
24 #if !defined(BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT)
25 # include "boost/mpl/eval_if.hpp"
26 # include "boost/mpl/identity.hpp"
27 # include "boost/mpl/protect.hpp"
28 # include "boost/mpl/transform.hpp"
30 # include "boost/preprocessor/cat.hpp"
31 # include "boost/preprocessor/repeat.hpp"
34 #include "boost/mpl/bool.hpp"
35 #include "boost/mpl/is_sequence.hpp"
36 #include "boost/variant/variant.hpp"
40 namespace detail
{ namespace variant
{
42 ///////////////////////////////////////////////////////////////////////////////
43 // (detail) metafunction specialization substitute
45 // Handles embedded variant types when substituting for recursive_variant_.
48 #if !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
51 BOOST_VARIANT_ENUM_PARAMS(typename T
)
52 , typename RecursiveVariant
53 BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(typename Arity
)
58 , BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T
)
61 , ::boost::recursive_variant_
62 BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity
)
65 typedef ::boost::variant
<
67 , BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T
)
72 BOOST_VARIANT_ENUM_PARAMS(typename T
)
73 , typename RecursiveVariant
74 BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(typename Arity
)
77 ::boost::variant
< BOOST_VARIANT_ENUM_PARAMS(T
) >
79 , ::boost::recursive_variant_
80 BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity
)
84 #if !defined(BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT)
86 private: // helpers, for metafunction result (below)
88 typedef typename
mpl::eval_if
<
89 ::boost::detail::variant::is_over_sequence
<T0
>
91 , make_variant_list
< BOOST_VARIANT_ENUM_PARAMS(T
) >
92 >::type initial_types
;
94 typedef typename
mpl::transform
<
96 , mpl::protect
< quoted_enable_recursive
<RecursiveVariant
,mpl::true_
> >
99 public: // metafunction result
101 typedef ::boost::variant
< types
> type
;
103 #else // defined(BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT)
105 private: // helpers, for metafunction result (below)
107 #define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS(z,N,_) \
108 typedef typename enable_recursive< \
112 >::type BOOST_PP_CAT(wknd_T,N); \
116 BOOST_VARIANT_LIMIT_TYPES
117 , BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS
121 #undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS
123 public: // metafunction result
125 typedef ::boost::variant
< BOOST_VARIANT_ENUM_PARAMS(wknd_T
) > type
;
127 #endif // BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT workaround
131 #else // defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
134 // no specializations: embedded variants unsupported on these compilers!
137 #endif // !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
139 }} // namespace detail::variant
141 ///////////////////////////////////////////////////////////////////////////////
142 // metafunction make_recursive_variant
144 // See docs and boost/variant/variant_fwd.hpp for more information.
146 template < BOOST_VARIANT_ENUM_PARAMS(typename T
) >
147 struct make_recursive_variant
149 public: // metafunction result
151 typedef boost::variant
<
152 detail::variant::recursive_flag
< T0
>
153 , BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T
)
158 ///////////////////////////////////////////////////////////////////////////////
159 // metafunction make_recursive_variant_over
161 // See docs and boost/variant/variant_fwd.hpp for more information.
163 template <typename Types
>
164 struct make_recursive_variant_over
166 private: // precondition assertions
168 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
169 BOOST_STATIC_ASSERT(( ::boost::mpl::is_sequence
<Types
>::value
));
172 public: // metafunction result
174 typedef typename make_recursive_variant
<
175 detail::variant::over_sequence
< Types
>
182 #endif // BOOST_VARIANT_RECURSIVE_VARIANT_HPP