1 //-----------------------------------------------------------------------------
2 // boost variant/detail/enable_recursive.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_DETAIL_ENABLE_RECURSIVE_HPP
14 #define BOOST_VARIANT_DETAIL_ENABLE_RECURSIVE_HPP
16 #include "boost/variant/detail/enable_recursive_fwd.hpp"
17 #include "boost/variant/variant_fwd.hpp"
19 #if !defined(BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT)
20 # include "boost/mpl/apply.hpp"
21 # include "boost/mpl/eval_if.hpp"
22 # include "boost/mpl/lambda.hpp"
25 #include "boost/variant/detail/substitute.hpp"
26 #include "boost/mpl/aux_/config/ctps.hpp"
27 #include "boost/mpl/bool_fwd.hpp"
28 #include "boost/mpl/if.hpp"
29 #include "boost/mpl/or.hpp"
30 #include "boost/type_traits/is_pointer.hpp"
31 #include "boost/type_traits/is_reference.hpp"
32 #include "boost/type_traits/is_same.hpp"
34 #include "boost/variant/recursive_wrapper.hpp"
37 namespace detail
{ namespace variant
{
39 #if !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
41 # define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(T,Dest,Source) \
42 substitute< T , Dest , Source > \
45 #else // defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
47 ///////////////////////////////////////////////////////////////////////////////
48 // (detail) class template rebind1
50 // Limited workaround in case 'substitute' metafunction unavailable.
53 template <typename T
, typename U1
>
57 typedef typename
mpl::lambda
<
62 typedef typename
mpl::eval_if
<
63 is_same
< le_
, mpl::identity
<T
> >
65 , mpl::apply1
<le_
, U1
>
69 # define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(T,Dest,Source) \
73 #endif // !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
75 ///////////////////////////////////////////////////////////////////////////////
76 // (detail) metafunction enable_recursive
78 // See boost/variant/detail/enable_recursive_fwd.hpp for more information.
81 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
83 template <typename T
, typename RecursiveVariant
, typename NoWrapper
>
84 struct enable_recursive
85 : BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(
86 T
, RecursiveVariant
, ::boost::recursive_variant_
91 template <typename T
, typename RecursiveVariant
>
92 struct enable_recursive
< T
,RecursiveVariant
,mpl::false_
>
94 private: // helpers, for metafunction result (below)
96 typedef typename
BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(
97 T
, RecursiveVariant
, ::boost::recursive_variant_
100 public: // metafunction result
102 // [Wrap with recursive_wrapper only if rebind really changed something:]
103 typedef typename
mpl::if_
<
110 , boost::recursive_wrapper
<t_
>
115 #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
117 template <typename T
, typename RecursiveVariant
, typename NoWrapper
>
118 struct enable_recursive
120 private: // helpers, for metafunction result (below)
122 typedef typename
BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(
123 T
, RecursiveVariant
, ::boost::recursive_variant_
126 public: // metafunction result
128 // [Wrap with recursive_wrapper only if rebind really changed something:]
129 typedef typename
mpl::if_
<
137 , boost::recursive_wrapper
<t_
>
142 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
144 ///////////////////////////////////////////////////////////////////////////////
145 // (detail) metafunction class quoted_enable_recursive
147 // Same behavior as enable_recursive metafunction (see above).
149 template <typename RecursiveVariant
, typename NoWrapper
>
150 struct quoted_enable_recursive
152 template <typename T
>
154 : enable_recursive
<T
, RecursiveVariant
, NoWrapper
>
159 }} // namespace detail::variant
162 #endif // BOOST_VARIANT_DETAIL_ENABLE_RECURSIVE_HPP