From 505466ff0edcf920dc73b1d94a5b38ceb3e62971 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Wed, 13 Apr 2016 00:56:17 +0200 Subject: [PATCH] added variadic make_tuple() function --- include/pybind11/cast.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index d0608f36..3fd9ab34 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -707,20 +707,24 @@ template inline object cast(const T &value, return_value_policy pol template inline T handle::cast() const { return pybind11::cast(*this); } template <> inline void handle::cast() const { return; } -template inline object handle::call(Args&&... args_) const { +template inline tuple make_tuple(Args&&... args_) { const size_t size = sizeof...(Args); std::array args { { object(detail::type_caster::type>::cast( - std::forward(args_), return_value_policy::reference, nullptr), false)... } + std::forward(args_), return_value_policy::automatic, nullptr), false)... } }; for (auto &arg_value : args) if (!arg_value) - throw cast_error("handle::call(): unable to convert input " - "arguments to Python objects"); - tuple args_tuple(size); + throw cast_error("make_tuple(): unable to convert arguments to Python objects"); + tuple result(size); int counter = 0; for (auto &arg_value : args) - PyTuple_SET_ITEM(args_tuple.ptr(), counter++, arg_value.release().ptr()); + PyTuple_SET_ITEM(result.ptr(), counter++, arg_value.release().ptr()); + return result; +} + +template inline object handle::call(Args&&... args) const { + tuple args_tuple = make_tuple(std::forward(args)...); object result(PyObject_CallObject(m_ptr, args_tuple.ptr()), false); if (!result) throw error_already_set();