recursive_wrapper_fwd.hpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 Eric Friedman, Itay Maman
  7. // Copyright (c) 2016-2024 Antony Polukhin
  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. #include <boost/type_traits/is_constructible.hpp>
  21. #include <boost/type_traits/is_nothrow_move_constructible.hpp>
  22. namespace boost {
  23. //////////////////////////////////////////////////////////////////////////
  24. // class template recursive_wrapper
  25. //
  26. // Enables recursive types in templates by breaking cyclic dependencies.
  27. //
  28. // For example:
  29. //
  30. // class my;
  31. //
  32. // typedef variant< int, recursive_wrapper<my> > var;
  33. //
  34. // class my {
  35. // var var_;
  36. // ...
  37. // };
  38. //
  39. template <typename T> class recursive_wrapper;
  40. ///////////////////////////////////////////////////////////////////////////////
  41. // metafunction is_constructible partial specializations.
  42. //
  43. // recursive_wrapper<T> is constructible only from T and recursive_wrapper<T>.
  44. //
  45. template <class T> struct is_constructible<recursive_wrapper<T>, T> : boost::true_type{};
  46. template <class T> struct is_constructible<recursive_wrapper<T>, const T> : boost::true_type{};
  47. template <class T> struct is_constructible<recursive_wrapper<T>, T&> : boost::true_type{};
  48. template <class T> struct is_constructible<recursive_wrapper<T>, const T&> : boost::true_type{};
  49. template <class T> struct is_constructible<recursive_wrapper<T>, recursive_wrapper<T> > : boost::true_type{};
  50. template <class T> struct is_constructible<recursive_wrapper<T>, const recursive_wrapper<T> > : boost::true_type{};
  51. template <class T> struct is_constructible<recursive_wrapper<T>, recursive_wrapper<T>& > : boost::true_type{};
  52. template <class T> struct is_constructible<recursive_wrapper<T>, const recursive_wrapper<T>& > : boost::true_type{};
  53. template <class T, class U> struct is_constructible<recursive_wrapper<T>, U > : boost::false_type{};
  54. template <class T, class U> struct is_constructible<recursive_wrapper<T>, const U > : boost::false_type{};
  55. template <class T, class U> struct is_constructible<recursive_wrapper<T>, U& > : boost::false_type{};
  56. template <class T, class U> struct is_constructible<recursive_wrapper<T>, const U& > : boost::false_type{};
  57. template <class T, class U> struct is_constructible<recursive_wrapper<T>, recursive_wrapper<U> > : boost::false_type{};
  58. template <class T, class U> struct is_constructible<recursive_wrapper<T>, const recursive_wrapper<U> > : boost::false_type{};
  59. template <class T, class U> struct is_constructible<recursive_wrapper<T>, recursive_wrapper<U>& > : boost::false_type{};
  60. template <class T, class U> struct is_constructible<recursive_wrapper<T>, const recursive_wrapper<U>& > : boost::false_type{};
  61. // recursive_wrapper is not nothrow move constructible, because it's constructor does dynamic memory allocation.
  62. // This specialisation is required to workaround GCC6 issue: https://svn.boost.org/trac/boost/ticket/12680
  63. template <class T> struct is_nothrow_move_constructible<recursive_wrapper<T> > : boost::false_type{};
  64. ///////////////////////////////////////////////////////////////////////////////
  65. // metafunction is_recursive_wrapper (modeled on code by David Abrahams)
  66. //
  67. // True if specified type matches recursive_wrapper<T>.
  68. //
  69. namespace detail {
  70. template <typename T>
  71. struct is_recursive_wrapper_impl
  72. : mpl::false_
  73. {
  74. };
  75. template <typename T>
  76. struct is_recursive_wrapper_impl< recursive_wrapper<T> >
  77. : mpl::true_
  78. {
  79. };
  80. } // namespace detail
  81. template< typename T > struct is_recursive_wrapper
  82. : public ::boost::integral_constant<bool,(::boost::detail::is_recursive_wrapper_impl<T>::value)>
  83. {
  84. public:
  85. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_recursive_wrapper,(T))
  86. };
  87. ///////////////////////////////////////////////////////////////////////////////
  88. // metafunction unwrap_recursive
  89. //
  90. // If specified type T matches recursive_wrapper<U>, then U; else T.
  91. //
  92. template <typename T>
  93. struct unwrap_recursive
  94. {
  95. typedef T type;
  96. BOOST_MPL_AUX_LAMBDA_SUPPORT(1,unwrap_recursive,(T))
  97. };
  98. template <typename T>
  99. struct unwrap_recursive< recursive_wrapper<T> >
  100. {
  101. typedef T type;
  102. BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(1,unwrap_recursive,(T))
  103. };
  104. } // namespace boost
  105. #endif // BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP