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;
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>());
84 template <
typename Func>
89 auto result = f_.template target<function_type>();
Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object.
#define PYBIND11_NAMESPACE
Internal data structure which holds metadata about a bound function (signature, overloads, etc.)
constexpr descr< N - 1 > _(char const(&text)[N])
conditional_t< std::is_same< Return, void >::value, void_type, Return > retval_type
bool same_type(const std::type_info &lhs, const std::type_info &rhs)
bool is_none() const
Equivalent to obj is None in Python.
bool load(handle src, bool convert)
#define NAMESPACE_END(name)
std::function< Return(Args...)> type
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
static handle cast(Func &&f_, return_value_policy policy, handle)
Return(*)(Args...) function_type
typename std::conditional< B, T, F >::type conditional_t
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
Helper type to replace 'void' in some expressions.
#define NAMESPACE_BEGIN(name)
#define PYBIND11_TYPE_CASTER(type, py_name)
const handle & inc_ref() const &
constexpr descr< 0 > concat()