1 // Copyright David Abrahams 2001.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef FORWARD_DWA20011215_HPP
6 # define FORWARD_DWA20011215_HPP
8 # include <boost/mpl/if.hpp>
9 # include <boost/type_traits/is_scalar.hpp>
10 # include <boost/type_traits/add_const.hpp>
11 # include <boost/type_traits/add_reference.hpp>
12 # include <boost/ref.hpp>
13 # include <boost/python/detail/value_arg.hpp>
14 # include <boost/python/detail/copy_ctor_mutates_rhs.hpp>
15 # include <boost/mpl/or.hpp>
17 namespace boost { namespace python { namespace objects {
19 // Very much like boost::reference_wrapper<T>, except that in this
20 // case T can be a reference already without causing a
21 // reference-to-reference error.
23 struct reference_to_value
25 typedef typename add_reference<typename add_const<T>::type>::type reference;
27 reference_to_value(reference x) : m_value(x) {}
28 reference get() const { return m_value; }
33 // A little metaprogram which selects the type to pass through an
34 // intermediate forwarding function when the destination argument type
39 mpl::or_<python::detail::copy_ctor_mutates_rhs<T>, is_scalar<T> >
41 , reference_to_value<T>
49 typedef typename unwrap_reference<T>::type& type;
53 struct unforward<reference_to_value<T> >
60 : python::detail::value_arg<
61 typename unwrap_reference<T>::type
67 struct unforward_cref<reference_to_value<T> >
68 : add_reference<typename add_const<T>::type>
74 typename reference_to_value<T>::reference
75 do_unforward(reference_to_value<T> const& x, int)
81 typename reference_wrapper<T>::type&
82 do_unforward(reference_wrapper<T> const& x, int)
88 T const& do_unforward(T const& x, ...)
93 }}} // namespace boost::python::objects
95 #endif // FORWARD_DWA20011215_HPP