/Src/Dependencies/Boost/boost/variant/detail/enable_recursive.hpp

http://hadesmem.googlecode.com/ · C++ Header · 162 lines · 100 code · 32 blank · 30 comment · 0 complexity · 4cac067761527a0392d3f5f69e2246b6 MD5 · raw file

  1. //-----------------------------------------------------------------------------
  2. // boost variant/detail/enable_recursive.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_DETAIL_ENABLE_RECURSIVE_HPP
  13. #define BOOST_VARIANT_DETAIL_ENABLE_RECURSIVE_HPP
  14. #include "boost/variant/detail/enable_recursive_fwd.hpp"
  15. #include "boost/variant/variant_fwd.hpp"
  16. #if !defined(BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT)
  17. # include "boost/mpl/apply.hpp"
  18. # include "boost/mpl/eval_if.hpp"
  19. # include "boost/mpl/lambda.hpp"
  20. #endif
  21. #include "boost/variant/detail/substitute.hpp"
  22. #include "boost/mpl/aux_/config/ctps.hpp"
  23. #include "boost/mpl/bool_fwd.hpp"
  24. #include "boost/mpl/if.hpp"
  25. #include "boost/mpl/or.hpp"
  26. #include "boost/type_traits/is_pointer.hpp"
  27. #include "boost/type_traits/is_reference.hpp"
  28. #include "boost/type_traits/is_same.hpp"
  29. #include "boost/variant/recursive_wrapper.hpp"
  30. namespace boost {
  31. namespace detail { namespace variant {
  32. #if !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
  33. # define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(T,Dest,Source) \
  34. substitute< T , Dest , Source > \
  35. /**/
  36. #else // defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
  37. ///////////////////////////////////////////////////////////////////////////////
  38. // (detail) class template rebind1
  39. //
  40. // Limited workaround in case 'substitute' metafunction unavailable.
  41. //
  42. template <typename T, typename U1>
  43. struct rebind1
  44. {
  45. private:
  46. typedef typename mpl::lambda<
  47. mpl::identity<T>
  48. >::type le_;
  49. public:
  50. typedef typename mpl::eval_if<
  51. is_same< le_, mpl::identity<T> >
  52. , le_ // identity<T>
  53. , mpl::apply1<le_, U1>
  54. >::type type;
  55. };
  56. # define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(T,Dest,Source) \
  57. rebind1< T , Dest > \
  58. /**/
  59. #endif // !defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
  60. ///////////////////////////////////////////////////////////////////////////////
  61. // (detail) metafunction enable_recursive
  62. //
  63. // See boost/variant/detail/enable_recursive_fwd.hpp for more information.
  64. //
  65. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  66. template <typename T, typename RecursiveVariant, typename NoWrapper>
  67. struct enable_recursive
  68. : BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(
  69. T, RecursiveVariant, ::boost::recursive_variant_
  70. )
  71. {
  72. };
  73. template <typename T, typename RecursiveVariant>
  74. struct enable_recursive< T,RecursiveVariant,mpl::false_ >
  75. {
  76. private: // helpers, for metafunction result (below)
  77. typedef typename BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(
  78. T, RecursiveVariant, ::boost::recursive_variant_
  79. )::type t_;
  80. public: // metafunction result
  81. // [Wrap with recursive_wrapper only if rebind really changed something:]
  82. typedef typename mpl::if_<
  83. mpl::or_<
  84. is_same< t_,T >
  85. , is_reference<t_>
  86. , is_pointer<t_>
  87. >
  88. , t_
  89. , boost::recursive_wrapper<t_>
  90. >::type type;
  91. };
  92. #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  93. template <typename T, typename RecursiveVariant, typename NoWrapper>
  94. struct enable_recursive
  95. {
  96. private: // helpers, for metafunction result (below)
  97. typedef typename BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(
  98. T, RecursiveVariant, ::boost::recursive_variant_
  99. )::type t_;
  100. public: // metafunction result
  101. // [Wrap with recursive_wrapper only if rebind really changed something:]
  102. typedef typename mpl::if_<
  103. mpl::or_<
  104. NoWrapper
  105. , is_same< t_,T >
  106. , is_reference<t_>
  107. , is_pointer<t_>
  108. >
  109. , t_
  110. , boost::recursive_wrapper<t_>
  111. >::type type;
  112. };
  113. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
  114. ///////////////////////////////////////////////////////////////////////////////
  115. // (detail) metafunction class quoted_enable_recursive
  116. //
  117. // Same behavior as enable_recursive metafunction (see above).
  118. //
  119. template <typename RecursiveVariant, typename NoWrapper>
  120. struct quoted_enable_recursive
  121. {
  122. template <typename T>
  123. struct apply
  124. : enable_recursive<T, RecursiveVariant, NoWrapper>
  125. {
  126. };
  127. };
  128. }} // namespace detail::variant
  129. } // namespace boost
  130. #endif // BOOST_VARIANT_DETAIL_ENABLE_RECURSIVE_HPP