recursive_wrapper_fwd.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/bool.hpp>
  17. #include "boost/mpl/aux_/config/ctps.hpp"
  18. #include "boost/mpl/aux_/lambda_support.hpp"
  19. #include <boost/type_traits/integral_constant.hpp>
  20. namespace boost {
  21. //////////////////////////////////////////////////////////////////////////
  22. // class template recursive_wrapper
  23. //
  24. // Enables recursive types in templates by breaking cyclic dependencies.
  25. //
  26. // For example:
  27. //
  28. // class my;
  29. //
  30. // typedef variant< int, recursive_wrapper<my> > var;
  31. //
  32. // class my {
  33. // var var_;
  34. // ...
  35. // };
  36. //
  37. template <typename T> class recursive_wrapper;
  38. ///////////////////////////////////////////////////////////////////////////////
  39. // metafunction is_recursive_wrapper (modeled on code by David Abrahams)
  40. //
  41. // True iff specified type matches recursive_wrapper<T>.
  42. //
  43. namespace detail {
  44. template <typename T>
  45. struct is_recursive_wrapper_impl
  46. : mpl::false_
  47. {
  48. };
  49. template <typename T>
  50. struct is_recursive_wrapper_impl< recursive_wrapper<T> >
  51. : mpl::true_
  52. {
  53. };
  54. } // namespace detail
  55. template< typename T > struct is_recursive_wrapper
  56. : public ::boost::integral_constant<bool,(::boost::detail::is_recursive_wrapper_impl<T>::value)>
  57. {
  58. public:
  59. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_recursive_wrapper,(T))
  60. };
  61. ///////////////////////////////////////////////////////////////////////////////
  62. // metafunction unwrap_recursive
  63. //
  64. // If specified type T matches recursive_wrapper<U>, then U; else T.
  65. //
  66. template <typename T>
  67. struct unwrap_recursive
  68. {
  69. typedef T type;
  70. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,unwrap_recursive,(T))
  71. };
  72. template <typename T>
  73. struct unwrap_recursive< recursive_wrapper<T> >
  74. {
  75. typedef T type;
  76. BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(1,unwrap_recursive,(T))
  77. };
  78. } // namespace boost
  79. #endif // BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP