[857] | 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 |
|
---|
| 15 | #ifndef BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP
|
---|
| 16 | #define BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP
|
---|
| 17 |
|
---|
| 18 | #include "boost/mpl/aux_/config/ctps.hpp"
|
---|
| 19 | #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
---|
| 20 | # include "boost/mpl/eval_if.hpp"
|
---|
| 21 | # include "boost/mpl/bool.hpp"
|
---|
| 22 | # include "boost/mpl/identity.hpp"
|
---|
| 23 | # include "boost/type.hpp"
|
---|
| 24 | #endif
|
---|
| 25 |
|
---|
| 26 | #include "boost/type_traits/detail/bool_trait_def.hpp"
|
---|
| 27 | #include "boost/mpl/aux_/lambda_support.hpp"
|
---|
| 28 |
|
---|
| 29 | namespace boost {
|
---|
| 30 |
|
---|
| 31 | //////////////////////////////////////////////////////////////////////////
|
---|
| 32 | // class template recursive_wrapper
|
---|
| 33 | //
|
---|
| 34 | // Enables recursive types in templates by breaking cyclic dependencies.
|
---|
| 35 | //
|
---|
| 36 | // For example:
|
---|
| 37 | //
|
---|
| 38 | // class my;
|
---|
| 39 | //
|
---|
| 40 | // typedef variant< int, recursive_wrapper<my> > var;
|
---|
| 41 | //
|
---|
| 42 | // class my {
|
---|
| 43 | // var var_;
|
---|
| 44 | // ...
|
---|
| 45 | // };
|
---|
| 46 | //
|
---|
| 47 | template <typename T> class recursive_wrapper;
|
---|
| 48 |
|
---|
| 49 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 50 | // metafunction is_recursive_wrapper (modeled on code by David Abrahams)
|
---|
| 51 | //
|
---|
| 52 | // True iff specified type matches recursive_wrapper<T>.
|
---|
| 53 | //
|
---|
| 54 |
|
---|
| 55 | namespace detail {
|
---|
| 56 |
|
---|
| 57 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
---|
| 58 |
|
---|
| 59 | template <typename T>
|
---|
| 60 | struct is_recursive_wrapper_impl
|
---|
| 61 | : mpl::false_
|
---|
| 62 | {
|
---|
| 63 | };
|
---|
| 64 |
|
---|
| 65 | template <typename T>
|
---|
| 66 | struct is_recursive_wrapper_impl< recursive_wrapper<T> >
|
---|
| 67 | : mpl::true_
|
---|
| 68 | {
|
---|
| 69 | };
|
---|
| 70 |
|
---|
| 71 | #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
---|
| 72 |
|
---|
| 73 | typedef char (&yes_recursive_wrapper_t)[1];
|
---|
| 74 | typedef char (&no_recursive_wrapper_t)[2];
|
---|
| 75 |
|
---|
| 76 | no_recursive_wrapper_t is_recursive_wrapper_test(...);
|
---|
| 77 |
|
---|
| 78 | template<typename T>
|
---|
| 79 | yes_recursive_wrapper_t is_recursive_wrapper_test(
|
---|
| 80 | type< ::boost::recursive_wrapper<T> >
|
---|
| 81 | );
|
---|
| 82 |
|
---|
| 83 | template<typename T>
|
---|
| 84 | struct is_recursive_wrapper_impl
|
---|
| 85 | {
|
---|
| 86 | BOOST_STATIC_CONSTANT(bool, value = (
|
---|
| 87 | sizeof(is_recursive_wrapper_test(type<T>()))
|
---|
| 88 | == sizeof(yes_recursive_wrapper_t)
|
---|
| 89 | ));
|
---|
| 90 | };
|
---|
| 91 |
|
---|
| 92 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
|
---|
| 93 |
|
---|
| 94 | } // namespace detail
|
---|
| 95 |
|
---|
| 96 | BOOST_TT_AUX_BOOL_TRAIT_DEF1(
|
---|
| 97 | is_recursive_wrapper
|
---|
| 98 | , T
|
---|
| 99 | , (::boost::detail::is_recursive_wrapper_impl<T>::value)
|
---|
| 100 | )
|
---|
| 101 |
|
---|
| 102 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 103 | // metafunction unwrap_recursive
|
---|
| 104 | //
|
---|
| 105 | // If specified type T matches recursive_wrapper<U>, then U; else T.
|
---|
| 106 | //
|
---|
| 107 |
|
---|
| 108 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
---|
| 109 |
|
---|
| 110 | template <typename T>
|
---|
| 111 | struct unwrap_recursive
|
---|
| 112 | {
|
---|
| 113 | typedef T type;
|
---|
| 114 |
|
---|
| 115 | BOOST_MPL_AUX_LAMBDA_SUPPORT(1,unwrap_recursive,(T))
|
---|
| 116 | };
|
---|
| 117 |
|
---|
| 118 | template <typename T>
|
---|
| 119 | struct unwrap_recursive< recursive_wrapper<T> >
|
---|
| 120 | {
|
---|
| 121 | typedef T type;
|
---|
| 122 |
|
---|
| 123 | BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(1,unwrap_recursive,(T))
|
---|
| 124 | };
|
---|
| 125 |
|
---|
| 126 | #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
---|
| 127 |
|
---|
| 128 | template <typename T>
|
---|
| 129 | struct unwrap_recursive
|
---|
| 130 | : mpl::eval_if<
|
---|
| 131 | is_recursive_wrapper<T>
|
---|
| 132 | , T
|
---|
| 133 | , mpl::identity< T >
|
---|
| 134 | >
|
---|
| 135 | {
|
---|
| 136 | BOOST_MPL_AUX_LAMBDA_SUPPORT(1,unwrap_recursive,(T))
|
---|
| 137 | };
|
---|
| 138 |
|
---|
| 139 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
|
---|
| 140 |
|
---|
| 141 | } // namespace boost
|
---|
| 142 |
|
---|
| 143 | #endif // BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP
|
---|