fix doc example typo
[boost.git] / boost / variant / recursive_wrapper_fwd.hpp
blob69a0ec701de27ed3fceb60e5429676f6da6aa10d
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
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)
15 #ifndef BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP
16 #define BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP
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
26 #include "boost/mpl/aux_/lambda_support.hpp"
28 // should be the last #include
29 #include "boost/type_traits/detail/bool_trait_def.hpp"
31 namespace boost {
33 //////////////////////////////////////////////////////////////////////////
34 // class template recursive_wrapper
36 // Enables recursive types in templates by breaking cyclic dependencies.
38 // For example:
40 // class my;
42 // typedef variant< int, recursive_wrapper<my> > var;
44 // class my {
45 // var var_;
46 // ...
47 // };
49 template <typename T> class recursive_wrapper;
51 ///////////////////////////////////////////////////////////////////////////////
52 // metafunction is_recursive_wrapper (modeled on code by David Abrahams)
54 // True iff specified type matches recursive_wrapper<T>.
57 namespace detail {
59 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
61 template <typename T>
62 struct is_recursive_wrapper_impl
63 : mpl::false_
67 template <typename T>
68 struct is_recursive_wrapper_impl< recursive_wrapper<T> >
69 : mpl::true_
73 #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
75 typedef char (&yes_recursive_wrapper_t)[1];
76 typedef char (&no_recursive_wrapper_t)[2];
78 no_recursive_wrapper_t is_recursive_wrapper_test(...);
80 template<typename T>
81 yes_recursive_wrapper_t is_recursive_wrapper_test(
82 type< ::boost::recursive_wrapper<T> >
85 template<typename T>
86 struct is_recursive_wrapper_impl
88 BOOST_STATIC_CONSTANT(bool, value = (
89 sizeof(is_recursive_wrapper_test(type<T>()))
90 == sizeof(yes_recursive_wrapper_t)
91 ));
94 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
96 } // namespace detail
98 BOOST_TT_AUX_BOOL_TRAIT_DEF1(
99 is_recursive_wrapper
101 , (::boost::detail::is_recursive_wrapper_impl<T>::value)
104 ///////////////////////////////////////////////////////////////////////////////
105 // metafunction unwrap_recursive
107 // If specified type T matches recursive_wrapper<U>, then U; else T.
110 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
112 template <typename T>
113 struct unwrap_recursive
115 typedef T type;
117 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,unwrap_recursive,(T))
120 template <typename T>
121 struct unwrap_recursive< recursive_wrapper<T> >
123 typedef T type;
125 BOOST_MPL_AUX_LAMBDA_SUPPORT_SPEC(1,unwrap_recursive,(T))
128 #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
130 template <typename T>
131 struct unwrap_recursive
132 : mpl::eval_if<
133 is_recursive_wrapper<T>
135 , mpl::identity< T >
138 BOOST_MPL_AUX_LAMBDA_SUPPORT(1,unwrap_recursive,(T))
141 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
143 } // namespace boost
145 #include "boost/type_traits/detail/bool_trait_undef.hpp"
147 #endif // BOOST_VARIANT_RECURSIVE_WRAPPER_FWD_HPP