Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:39

0001 // Copyright David Abrahams 2001.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef FORWARD_DWA20011215_HPP
0006 # define FORWARD_DWA20011215_HPP
0007 
0008 # include <boost/mpl/if.hpp>
0009 # include <boost/ref.hpp>
0010 # include <boost/python/detail/value_arg.hpp>
0011 # include <boost/python/detail/type_traits.hpp>
0012 # include <boost/python/detail/copy_ctor_mutates_rhs.hpp>
0013 # include <boost/mpl/or.hpp>
0014 
0015 namespace boost { namespace python { namespace objects { 
0016 
0017 // Very much like boost::reference_wrapper<T>, except that in this
0018 // case T can be a reference already without causing a
0019 // reference-to-reference error.
0020 template <class T>
0021 struct reference_to_value
0022 {
0023     typedef typename boost::python::detail::add_lvalue_reference<typename
0024         boost::python::detail::add_const<T>::type>::type reference;
0025     
0026     reference_to_value(reference x) : m_value(x) {}
0027     reference get() const { return m_value; }
0028  private:
0029     reference m_value;
0030 };
0031 
0032 // A little metaprogram which selects the type to pass through an
0033 // intermediate forwarding function when the destination argument type
0034 // is T.
0035 template <class T>
0036 struct forward
0037     : mpl::if_<
0038           mpl::or_<python::detail::copy_ctor_mutates_rhs<T>, boost::python::detail::is_scalar<T> >
0039         , T
0040         , reference_to_value<T>
0041       >
0042 {
0043 };
0044 
0045 template<typename T>
0046 struct unforward
0047 {
0048     typedef typename unwrap_reference<T>::type& type;
0049 };
0050 
0051 template<typename T>
0052 struct unforward<reference_to_value<T> >
0053 {
0054     typedef T type;
0055 };
0056 
0057 template <typename T>
0058 struct unforward_cref
0059   : python::detail::value_arg<
0060         typename unwrap_reference<T>::type
0061     >
0062 {
0063 };
0064 
0065 template<typename T>
0066 struct unforward_cref<reference_to_value<T> >
0067   : boost::python::detail::add_lvalue_reference<typename boost::python::detail::add_const<T>::type>
0068 {
0069 };
0070 
0071 
0072 template <class T>
0073 typename reference_to_value<T>::reference
0074 do_unforward(reference_to_value<T> const& x, int)
0075 {
0076     return x.get();
0077 }
0078 
0079 template <class T>
0080 typename reference_wrapper<T>::type&
0081 do_unforward(reference_wrapper<T> const& x, int)
0082 {
0083     return x.get();
0084 }
0085 
0086 template <class T>
0087 T const& do_unforward(T const& x, ...)
0088 {
0089     return x;
0090 }
0091 
0092 }}} // namespace boost::python::objects
0093 
0094 #endif // FORWARD_DWA20011215_HPP