/Src/Dependencies/Boost/boost/variant/recursive_variant.hpp

http://hadesmem.googlecode.com/ · C++ Header · 193 lines · 128 code · 35 blank · 30 comment · 0 complexity · 2d3f262275fdfbd0f8020a8672864e76 MD5 · raw file

  1. //-----------------------------------------------------------------------------
  2. // boost variant/recursive_variant.hpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2003
  7. // Eric Friedman
  8. //
  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)
  12. #ifndef BOOST_VARIANT_RECURSIVE_VARIANT_HPP
  13. #define BOOST_VARIANT_RECURSIVE_VARIANT_HPP
  14. #include "boost/variant/variant_fwd.hpp"
  15. #include "boost/variant/detail/enable_recursive.hpp"
  16. #include "boost/variant/detail/substitute_fwd.hpp"
  17. #include "boost/variant/detail/make_variant_list.hpp"
  18. #include "boost/variant/detail/over_sequence.hpp"
  19. #include "boost/mpl/aux_/lambda_arity_param.hpp"
  20. #include "boost/mpl/equal.hpp"
  21. #include "boost/mpl/eval_if.hpp"
  22. #include "boost/mpl/identity.hpp"
  23. #include "boost/mpl/if.hpp"
  24. #include "boost/mpl/protect.hpp"
  25. #include "boost/mpl/transform.hpp"
  26. #include "boost/type_traits/is_same.hpp"
  27. #include "boost/preprocessor/cat.hpp"
  28. #include "boost/preprocessor/repeat.hpp"
  29. #include "boost/mpl/bool.hpp"
  30. #include "boost/mpl/is_sequence.hpp"
  31. #include "boost/variant/variant.hpp"
  32. namespace boost {
  33. namespace detail { namespace variant {
  34. ///////////////////////////////////////////////////////////////////////////////
  35. // (detail) metafunction specialization substitute
  36. //
  37. // Handles embedded variant types when substituting for recursive_variant_.
  38. //
  39. #if !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
  40. template <
  41. BOOST_VARIANT_ENUM_PARAMS(typename T)
  42. , typename RecursiveVariant
  43. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(typename Arity)
  44. >
  45. struct substitute<
  46. ::boost::variant<
  47. recursive_flag< T0 >
  48. , BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T)
  49. >
  50. , RecursiveVariant
  51. , ::boost::recursive_variant_
  52. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity)
  53. >
  54. {
  55. typedef ::boost::variant<
  56. recursive_flag< T0 >
  57. , BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T)
  58. > type;
  59. };
  60. template <
  61. BOOST_VARIANT_ENUM_PARAMS(typename T)
  62. , typename RecursiveVariant
  63. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(typename Arity)
  64. >
  65. struct substitute<
  66. ::boost::variant<
  67. ::boost::detail::variant::over_sequence< T0 >
  68. , BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T)
  69. >
  70. , RecursiveVariant
  71. , ::boost::recursive_variant_
  72. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity)
  73. >
  74. {
  75. private:
  76. typedef T0 initial_types;
  77. typedef typename mpl::transform<
  78. initial_types
  79. , mpl::protect< quoted_enable_recursive<RecursiveVariant,mpl::true_> >
  80. >::type types;
  81. public:
  82. typedef typename mpl::if_<
  83. mpl::equal<initial_types, types, ::boost::is_same<mpl::_1, mpl::_2> >
  84. , ::boost::variant<
  85. ::boost::detail::variant::over_sequence< T0 >
  86. , BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T)
  87. >
  88. , ::boost::variant< over_sequence<types> >
  89. >::type type;
  90. };
  91. template <
  92. BOOST_VARIANT_ENUM_PARAMS(typename T)
  93. , typename RecursiveVariant
  94. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(typename Arity)
  95. >
  96. struct substitute<
  97. ::boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >
  98. , RecursiveVariant
  99. , ::boost::recursive_variant_
  100. BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity)
  101. >
  102. {
  103. private: // helpers, for metafunction result (below)
  104. #define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS(z,N,_) \
  105. typedef typename enable_recursive< \
  106. BOOST_PP_CAT(T,N) \
  107. , RecursiveVariant \
  108. , mpl::true_ \
  109. >::type BOOST_PP_CAT(wknd_T,N); \
  110. /**/
  111. BOOST_PP_REPEAT(
  112. BOOST_VARIANT_LIMIT_TYPES
  113. , BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS
  114. , _
  115. )
  116. #undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS
  117. public: // metafunction result
  118. typedef ::boost::variant< BOOST_VARIANT_ENUM_PARAMS(wknd_T) > type;
  119. };
  120. #else // defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
  121. //
  122. // no specializations: embedded variants unsupported on these compilers!
  123. //
  124. #endif // !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
  125. }} // namespace detail::variant
  126. ///////////////////////////////////////////////////////////////////////////////
  127. // metafunction make_recursive_variant
  128. //
  129. // See docs and boost/variant/variant_fwd.hpp for more information.
  130. //
  131. template < BOOST_VARIANT_ENUM_PARAMS(typename T) >
  132. struct make_recursive_variant
  133. {
  134. public: // metafunction result
  135. typedef boost::variant<
  136. detail::variant::recursive_flag< T0 >
  137. , BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T)
  138. > type;
  139. };
  140. ///////////////////////////////////////////////////////////////////////////////
  141. // metafunction make_recursive_variant_over
  142. //
  143. // See docs and boost/variant/variant_fwd.hpp for more information.
  144. //
  145. template <typename Types>
  146. struct make_recursive_variant_over
  147. {
  148. private: // precondition assertions
  149. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  150. BOOST_STATIC_ASSERT(( ::boost::mpl::is_sequence<Types>::value ));
  151. #endif
  152. public: // metafunction result
  153. typedef typename make_recursive_variant<
  154. detail::variant::over_sequence< Types >
  155. >::type type;
  156. };
  157. } // namespace boost
  158. #endif // BOOST_VARIANT_RECURSIVE_VARIANT_HPP