recursive_wrapper_fwd.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. //-----------------------------------------------------------------------------
  2. // boost variant/recursive_wrapper_fwd.hpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2002
  7. // Eric Friedman, Itay Maman
  8. //
  9. // Portions Copyright (C) 2002 David Abrahams
  10. //
  11. // Distributed under the Boost Software License, Version 1.0. (See
  12. // accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP
  15. #define BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP
  16. #include "boost/mpl/aux_/config/ctps.hpp"
  17. #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  18. # include "boost/mpl/eval_if.hpp"
  19. # include "boost/mpl/bool.hpp"
  20. # include "boost/mpl/identity.hpp"
  21. # include "boost/type.hpp"
  22. #endif
  23. #include "boost/mpl/aux_/lambda_support.hpp"
  24. // should be the last #include
  25. #include "boost/type_traits/detail/bool_trait_def.hpp"
  26. namespace boost {
  27. //////////////////////////////////////////////////////////////////////////
  28. // class template recursive_wrapper
  29. //
  30. // Enables recursive types in templates by breaking cyclic dependencies.
  31. //
  32. // For example:
  33. //
  34. // class my;
  35. //
  36. // typedef variant< int, recursive_wrapper<my> > var;
  37. //
  38. // class my {
  39. // var var_;
  40. // ...
  41. // };
  42. //
  43. template <typename T> class recursive_wrapper;
  44. ///////////////////////////////////////////////////////////////////////////////
  45. // metafunction is_recursive_wrapper (modeled on code by David Abrahams)
  46. //
  47. // True iff specified type matches recursive_wrapper<T>.
  48. //
  49. namespace detail {
  50. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  51. template <typename T>
  52. struct is_recursive_wrapper_impl
  53. : mpl::false_
  54. {
  55. };
  56. template <typename T>
  57. struct is_recursive_wrapper_impl< recursive_wrapper<T> >
  58. : mpl::true_
  59. {
  60. };
  61. #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  62. typedef char (&yes_recursive_wrapper_t)[1];
  63. typedef char (&no_recursive_wrapper_t)[2];
  64. no_recursive_wrapper_t is_recursive_wrapper_test(...);
  65. template<typename T>
  66. yes_recursive_wrapper_t is_recursive_wrapper_test(
  67. type< ::boost::recursive_wrapper<T> >
  68. );
  69. template<typename T>
  70. struct is_recursive_wrapper_impl
  71. {
  72. BOOST_STATIC_CONSTANT(bool, value = (
  73. sizeof(is_recursive_wrapper_test(type<T>()))
  74. == sizeof(yes_recursive_wrapper_t)
  75. ));
  76. };
  77. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
  78. } // namespace detail
  79. BOOST_TT_AUX_BOOL_TRAIT_DEF1(
  80. is_recursive_wrapper
  81. , T
  82. , (::boost::detail::is_recursive_wrapper_impl<T>::value)
  83. )
  84. ///////////////////////////////////////////////////////////////////////////////
  85. // metafunction unwrap_recursive
  86. //
  87. // If specified type T matches recursive_wrapper<U>, then U; else T.
  88. //
  89. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  90. template <typename T>
  91. struct unwrap_recursive
  92. {
  93. typedef T type;
  94. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,unwrap_recursive,(T))
  95. };
  96. template <typename T>
  97. struct unwrap_recursive< recursive_wrapper<T> >
  98. {
  99. typedef T type;
  100. BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(1,unwrap_recursive,(T))
  101. };
  102. #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  103. template <typename T>
  104. struct unwrap_recursive
  105. : mpl::eval_if<
  106. is_recursive_wrapper<T>
  107. , T
  108. , mpl::identity< T >
  109. >
  110. {
  111. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,unwrap_recursive,(T))
  112. };
  113. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
  114. } // namespace boost
  115. #include "boost/type_traits/detail/bool_trait_undef.hpp"
  116. #endif // BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP