]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/include/boost/python/object/forward.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / python / include / boost / python / object / forward.hpp
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
7
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>
16
17 namespace boost { namespace python { namespace objects {
18
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.
22 template <class T>
23 struct reference_to_value
24 {
25 typedef typename add_reference<typename add_const<T>::type>::type reference;
26
27 reference_to_value(reference x) : m_value(x) {}
28 reference get() const { return m_value; }
29 private:
30 reference m_value;
31 };
32
33 // A little metaprogram which selects the type to pass through an
34 // intermediate forwarding function when the destination argument type
35 // is T.
36 template <class T>
37 struct forward
38 : mpl::if_<
39 mpl::or_<python::detail::copy_ctor_mutates_rhs<T>, is_scalar<T> >
40 , T
41 , reference_to_value<T>
42 >
43 {
44 };
45
46 template<typename T>
47 struct unforward
48 {
49 typedef typename unwrap_reference<T>::type& type;
50 };
51
52 template<typename T>
53 struct unforward<reference_to_value<T> >
54 {
55 typedef T type;
56 };
57
58 template <typename T>
59 struct unforward_cref
60 : python::detail::value_arg<
61 typename unwrap_reference<T>::type
62 >
63 {
64 };
65
66 template<typename T>
67 struct unforward_cref<reference_to_value<T> >
68 : add_reference<typename add_const<T>::type>
69 {
70 };
71
72
73 template <class T>
74 typename reference_to_value<T>::reference
75 do_unforward(reference_to_value<T> const& x, int)
76 {
77 return x.get();
78 }
79
80 template <class T>
81 typename reference_wrapper<T>::type&
82 do_unforward(reference_wrapper<T> const& x, int)
83 {
84 return x.get();
85 }
86
87 template <class T>
88 T const& do_unforward(T const& x, ...)
89 {
90 return x;
91 }
92
93 }}} // namespace boost::python::objects
94
95 #endif // FORWARD_DWA20011215_HPP