enable_recursive.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. # define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(T,Dest,Source) \
  33. substitute< T , Dest , Source > \
  34. /**/
  35. ///////////////////////////////////////////////////////////////////////////////
  36. // (detail) metafunction enable_recursive
  37. //
  38. // See boost/variant/detail/enable_recursive_fwd.hpp for more information.
  39. //
  40. template <typename T, typename RecursiveVariant, typename NoWrapper>
  41. struct enable_recursive
  42. : BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(
  43. T, RecursiveVariant, ::boost::recursive_variant_
  44. )
  45. {
  46. };
  47. template <typename T, typename RecursiveVariant>
  48. struct enable_recursive< T,RecursiveVariant,mpl::false_ >
  49. {
  50. private: // helpers, for metafunction result (below)
  51. typedef typename BOOST_VARIANT_AUX_ENABLE_RECURSIVE_IMPL(
  52. T, RecursiveVariant, ::boost::recursive_variant_
  53. )::type t_;
  54. public: // metafunction result
  55. // [Wrap with recursive_wrapper only if rebind really changed something:]
  56. typedef typename mpl::if_<
  57. mpl::or_<
  58. is_same< t_,T >
  59. , is_reference<t_>
  60. , is_pointer<t_>
  61. >
  62. , t_
  63. , boost::recursive_wrapper<t_>
  64. >::type type;
  65. };
  66. ///////////////////////////////////////////////////////////////////////////////
  67. // (detail) metafunction class quoted_enable_recursive
  68. //
  69. // Same behavior as enable_recursive metafunction (see above).
  70. //
  71. template <typename RecursiveVariant, typename NoWrapper>
  72. struct quoted_enable_recursive
  73. {
  74. template <typename T>
  75. struct apply
  76. : enable_recursive<T, RecursiveVariant, NoWrapper>
  77. {
  78. };
  79. };
  80. }} // namespace detail::variant
  81. } // namespace boost
  82. #endif // BOOST_VARIANT_DETAIL_ENABLE_RECURSIVE_HPP