[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/boostorg/python/develop/include/boost/python/object/forward.hpp [Back]  [Original]

// Copyright David Abrahams 2001.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef FORWARD_DWA20011215_HPP
# define FORWARD_DWA20011215_HPP

# include 
# include 
# include 
# include 
# include 
# include 

namespace boost { namespace python { namespace objects { 

// Very much like boost::reference_wrapper, except that in this
// case T can be a reference already without causing a
// reference-to-reference error.
template 
struct reference_to_value
{
    typedef typename boost::python::detail::add_lvalue_reference::type reference;
    
    reference_to_value(reference x) : m_value(x) {}
    reference get() const { return m_value; }
 private:
    reference m_value;
};

// A little metaprogram which selects the type to pass through an
// intermediate forwarding function when the destination argument type
// is T.
template 
struct forward
    : mpl::if_<
          mpl::or_
        , T
        , reference_to_value
      >
{
};

template
struct unforward
{
    typedef typename unwrap_reference::type& type;
};

template
struct unforward
{
    typedef T type;
};

template 
struct unforward_cref
  : python::detail::value_arg<
        typename unwrap_reference::type
    >
{
};

template
struct unforward_cref
  : boost::python::detail::add_lvalue_reference
{
};


template 
typename reference_to_value::reference
do_unforward(reference_to_value const& x, int)
{
    return x.get();
}

template 
typename reference_wrapper::type&
do_unforward(reference_wrapper const& x, int)
{
    return x.get();
}

template 
T const& do_unforward(T const& x, ...)
{
    return x;
}

}}} // namespace boost::python::objects

#endif // FORWARD_DWA20011215_HPP

Web Proxy Viewer  |  New URL  |  Original Page