18 template <typename Return, typename... Args>
20 using type = std::function<Return(Args...)>;
28 if (!convert)
return false;
32 if (!isinstance<function>(src))
35 auto func = reinterpret_borrow<function>(src);
45 if (
auto cfunc =
func.cpp_function()) {
46 auto c = reinterpret_borrow<capsule>(PyCFunction_GET_SELF(cfunc.ptr()));
49 if (rec && rec->is_stateless &&
60 func_handle(
function&& f_) :
f(std::move(f_)) {}
61 func_handle(
const func_handle&) =
default;
64 function kill_f(std::move(
f));
71 func_wrapper(func_handle&& hf): hfunc(std::move(hf)) {}
72 Return operator()(Args...
args)
const {
74 object retval(hfunc.f(std::forward<Args>(
args)...));
76 return (retval.template cast<Return>());
80 value = func_wrapper(func_handle(std::move(
func)));
84 template <
typename Func>
89 auto result = f_.template target<function_type>();
typename std::conditional< B, T, F >::type conditional_t
Return(*)(Args...) function_type
static handle cast(Func &&f_, return_value_policy policy, handle)
conditional_t< std::is_same< Return, void >::value, void_type, Return > retval_type
bool load(handle src, bool convert)
#define PYBIND11_NAMESPACE
bool same_type(const std::type_info &lhs, const std::type_info &rhs)
const handle & inc_ref() const &
bool convert(const int &y)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
constexpr descr< 0 > concat()
Helper type to replace 'void' in some expressions.
Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object.
Internal data structure which holds metadata about a bound function (signature, overloads, etc.)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
#define PYBIND11_TYPE_CASTER(type, py_name)
#define PYBIND11_NAMESPACE_END(name)
#define PYBIND11_NAMESPACE_BEGIN(name)