/* pybind11/functional.h: std::function<> support Copyright (c) 2016 Wenzel Jakob All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. */ #pragma once #include "pybind11.h" #include NAMESPACE_BEGIN(pybind11) NAMESPACE_BEGIN(detail) template struct type_caster> { typedef std::function type; typedef typename std::conditional::value, void_type, Return>::type retval_type; public: bool load(handle src_, bool) { src_ = detail::get_function(src_); if (!src_ || !PyCallable_Check(src_.ptr())) return false; object src(src_, true); value = [src](Args... args) -> Return { gil_scoped_acquire acq; object retval(src(std::move(args)...)); /* Visual studio 2015 parser issue: need parentheses around this expression */ return (retval.template cast()); }; return true; } template static handle cast(Func &&f_, return_value_policy policy, handle /* parent */) { return cpp_function(std::forward(f_), policy).release(); } PYBIND11_TYPE_CASTER(type, _("function<") + type_caster>::name() + _(" -> ") + type_caster::name() + _(">")); }; NAMESPACE_END(detail) NAMESPACE_END(pybind11)