1 // Copyright David Abrahams and Nikolay Mladenov 2003.
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 RETURN_ARG_DWA2003719_HPP
6 # define RETURN_ARG_DWA2003719_HPP
7 # include <boost/python/default_call_policies.hpp>
8 # include <boost/python/detail/none.hpp>
9 # include <boost/python/detail/value_arg.hpp>
11 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
12 # include <boost/python/converter/pytype_function.hpp>
15 # include <boost/python/detail/type_traits.hpp>
17 # include <boost/mpl/int.hpp>
18 # include <boost/mpl/at.hpp>
20 # include <boost/static_assert.hpp>
21 # include <boost/python/refcount.hpp>
25 namespace boost { namespace python {
29 template <std::size_t>
30 struct return_arg_pos_argument_must_be_positive
31 # if defined(__GNUC__) || defined(__EDG__)
38 template <class T> struct apply
42 static bool convertible()
47 PyObject *operator()( typename value_arg<T>::type ) const
51 #ifndef BOOST_PYTHON_NO_PY_SIGNATURES
52 PyTypeObject const *get_pytype() const { return converter::expected_pytype_for_arg<T>::get_pytype() ; }
61 , class Base = default_call_policies
63 struct return_arg : Base
66 BOOST_STATIC_CONSTANT(bool, legal = arg_pos > 0);
69 typedef typename mpl::if_c<
72 , detail::return_arg_pos_argument_must_be_positive<arg_pos>
73 // we could default to the base result_converter in case or
74 // arg_pos==0 since return arg 0 means return result, but I
75 // think it is better to issue an error instead, cause it can
77 >::type result_converter;
79 template <class ArgumentPackage>
80 static PyObject* postcall(ArgumentPackage const& args, PyObject* result)
82 // In case of arg_pos == 0 we could simply return Base::postcall,
83 // but this is redundant
84 BOOST_STATIC_ASSERT(arg_pos > 0);
86 result = Base::postcall(args,result);
90 return incref( detail::get(mpl::int_<arg_pos-1>(),args) );
94 struct extract_return_type : mpl::at_c<Sig, arg_pos>
101 class Base = default_call_policies
107 }} // namespace boost::python
109 #endif // RETURN_ARG_DWA2003719_HPP