19template <
typename Return,
typename... Args>
21 using type = std::function<Return(Args...)>;
35 if (!isinstance<function>(src)) {
39 auto func = reinterpret_borrow<function>(src);
49 if (
auto cfunc = func.cpp_function()) {
50 auto *cfunc_self = PyCFunction_GET_SELF(cfunc.ptr());
51 if (isinstance<capsule>(cfunc_self)) {
52 auto c = reinterpret_borrow<capsule>(cfunc_self);
55 while (rec !=
nullptr) {
58 *
reinterpret_cast<const std::type_info *
>(rec->data[1]))) {
62 value = ((capture *) &rec->data)->f;
76#if !(defined(_MSC_VER) && _MSC_VER == 1916 && defined(PYBIND11_CPP17))
83 func_handle(
const func_handle &f_) { operator=(f_); }
84 func_handle &operator=(
const func_handle &f_) {
98 explicit func_wrapper(func_handle &&hf) noexcept : hfunc(std::move(hf)) {}
99 Return operator()(Args...
args)
const {
101 object retval(hfunc.f(std::forward<Args>(
args)...));
103 return (retval.template cast<Return>());
107 value = func_wrapper(func_handle(std::move(func)));
111 template <
typename Func>
117 auto result = f_.template target<function_type>();
Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object.
\rst Holds a reference to a Python object (no reference counting)
const handle & inc_ref() const &
\rst Manually increase the reference count of the Python object.
handle release()
\rst Resets the internal pointer to nullptr without decreasing the object's reference count.
#define PYBIND11_NAMESPACE_END(name)
#define PYBIND11_NAMESPACE_BEGIN(name)
typename std::conditional< B, T, F >::type conditional_t
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
constexpr descr< N - 1 > const_name(char const (&text)[N])
constexpr descr< 0 > concat()
bool same_type(const std::type_info &lhs, const std::type_info &rhs)
Internal data structure which holds metadata about a bound function (signature, overloads,...
bool load(handle src, bool convert)
static handle cast(Func &&f_, return_value_policy policy, handle)
Return(*)(Args...) function_type
PYBIND11_TYPE_CASTER(type, const_name("Callable[[")+concat(make_caster< Args >::name...)+const_name("], ")+make_caster< retval_type >::name+const_name("]"))
conditional_t< std::is_same< Return, void >::value, void_type, Return > retval_type
Helper type to replace 'void' in some expressions.