Skip to content

Commit 505466f

Browse files
committed
added variadic make_tuple() function
1 parent 2c5d560 commit 505466f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

include/pybind11/cast.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -707,20 +707,24 @@ template <typename T> inline object cast(const T &value, return_value_policy pol
707707
template <typename T> inline T handle::cast() const { return pybind11::cast<T>(*this); }
708708
template <> inline void handle::cast() const { return; }
709709

710-
template <typename... Args> inline object handle::call(Args&&... args_) const {
710+
template <typename... Args> inline tuple make_tuple(Args&&... args_) {
711711
const size_t size = sizeof...(Args);
712712
std::array<object, size> args {
713713
{ object(detail::type_caster<typename detail::intrinsic_type<Args>::type>::cast(
714-
std::forward<Args>(args_), return_value_policy::reference, nullptr), false)... }
714+
std::forward<Args>(args_), return_value_policy::automatic, nullptr), false)... }
715715
};
716716
for (auto &arg_value : args)
717717
if (!arg_value)
718-
throw cast_error("handle::call(): unable to convert input "
719-
"arguments to Python objects");
720-
tuple args_tuple(size);
718+
throw cast_error("make_tuple(): unable to convert arguments to Python objects");
719+
tuple result(size);
721720
int counter = 0;
722721
for (auto &arg_value : args)
723-
PyTuple_SET_ITEM(args_tuple.ptr(), counter++, arg_value.release().ptr());
722+
PyTuple_SET_ITEM(result.ptr(), counter++, arg_value.release().ptr());
723+
return result;
724+
}
725+
726+
template <typename... Args> inline object handle::call(Args&&... args) const {
727+
tuple args_tuple = make_tuple(std::forward<Args>(args)...);
724728
object result(PyObject_CallObject(m_ptr, args_tuple.ptr()), false);
725729
if (!result)
726730
throw error_already_set();

0 commit comments

Comments
 (0)