diff --git a/include/pybind11/common.h b/include/pybind11/common.h index fb8504cc..a1ee28ca 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -202,17 +202,6 @@ extern "C" { } \ PyObject *pybind11_init() -// Function return value and argument type deduction support. When compiling under C++17 these -// differ as C++17 makes the noexcept specifier part of the function type, while it is not part of -// the type under earlier standards. -#ifdef __cpp_noexcept_function_type -# define PYBIND11_NOEXCEPT_TPL_ARG , bool NoExceptions -# define PYBIND11_NOEXCEPT_SPECIFIER noexcept(NoExceptions) -#else -# define PYBIND11_NOEXCEPT_TPL_ARG -# define PYBIND11_NOEXCEPT_SPECIFIER -#endif - NAMESPACE_BEGIN(pybind11) using ssize_t = Py_ssize_t; @@ -643,16 +632,16 @@ struct nodelete { template void operator()(T*) { } }; NAMESPACE_BEGIN(detail) template struct overload_cast_impl { - template - constexpr auto operator()(Return (*pf)(Args...) PYBIND11_NOEXCEPT_SPECIFIER) const noexcept + template + constexpr auto operator()(Return (*pf)(Args...)) const noexcept -> decltype(pf) { return pf; } - template - constexpr auto operator()(Return (Class::*pmf)(Args...) PYBIND11_NOEXCEPT_SPECIFIER, std::false_type = {}) const noexcept + template + constexpr auto operator()(Return (Class::*pmf)(Args...), std::false_type = {}) const noexcept -> decltype(pmf) { return pmf; } - template - constexpr auto operator()(Return (Class::*pmf)(Args...) const PYBIND11_NOEXCEPT_SPECIFIER, std::true_type) const noexcept + template + constexpr auto operator()(Return (Class::*pmf)(Args...) const, std::true_type) const noexcept -> decltype(pmf) { return pmf; } }; NAMESPACE_END(detail) diff --git a/include/pybind11/functional.h b/include/pybind11/functional.h index 8e7e75e6..b5ed4350 100644 --- a/include/pybind11/functional.h +++ b/include/pybind11/functional.h @@ -15,11 +15,11 @@ NAMESPACE_BEGIN(pybind11) NAMESPACE_BEGIN(detail) -template -struct type_caster> { - using type = std::function; +template +struct type_caster> { + using type = std::function; using retval_type = conditional_t::value, void_type, Return>; - using function_type = Return (*) (Args...) PYBIND11_NOEXCEPT_SPECIFIER; + using function_type = Return (*) (Args...); public: bool load(handle src_, bool) { diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 50eb682d..5d78c3a6 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -1140,23 +1140,22 @@ template struct handle_type_name> { NAMESPACE_END(detail) -template +template detail::vectorize_helper -vectorize(const Func &f, Return (*) (Args ...) PYBIND11_NOEXCEPT_SPECIFIER) { +vectorize(const Func &f, Return (*) (Args ...)) { return detail::vectorize_helper(f); } -template -detail::vectorize_helper -vectorize(Return (*f) (Args ...) PYBIND11_NOEXCEPT_SPECIFIER) { +template +detail::vectorize_helper +vectorize(Return (*f) (Args ...)) { return vectorize(f, f); } -template +template ::type::operator())>::type> auto vectorize(Func &&f) -> decltype( - vectorize(std::forward(f), (typename detail::remove_class::type::operator())>::type *) nullptr)) { - return vectorize(std::forward(f), (typename detail::remove_class::type::operator())>::type *) nullptr); + vectorize(std::forward(f), (FuncType *) nullptr)) { + return vectorize(std::forward(f), (FuncType *) nullptr); } NAMESPACE_END(pybind11) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index f022c0b4..5a604cd2 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -44,30 +44,31 @@ public: cpp_function() { } /// Construct a cpp_function from a vanilla function pointer - template - cpp_function(Return (*f)(Args...) PYBIND11_NOEXCEPT_SPECIFIER, const Extra&... extra) { + template + cpp_function(Return (*f)(Args...), const Extra&... extra) { initialize(f, f, extra...); } /// Construct a cpp_function from a lambda function (possibly with internal state) - template cpp_function(Func &&f, const Extra&... extra) { + template ::type::operator())>::type> + cpp_function(Func &&f, const Extra&... extra) { initialize(std::forward(f), - (typename detail::remove_class::type::operator())>::type *) nullptr, extra...); + (FuncType *) nullptr, extra...); } /// Construct a cpp_function from a class method (non-const) - template - cpp_function(Return (Class::*f)(Arg...) PYBIND11_NOEXCEPT_SPECIFIER, const Extra&... extra) { + template + cpp_function(Return (Class::*f)(Arg...), const Extra&... extra) { initialize([f](Class *c, Arg... args) -> Return { return (c->*f)(args...); }, - (Return (*) (Class *, Arg...) PYBIND11_NOEXCEPT_SPECIFIER) nullptr, extra...); + (Return (*) (Class *, Arg...)) nullptr, extra...); } /// Construct a cpp_function from a class method (const) - template - cpp_function(Return (Class::*f)(Arg...) const PYBIND11_NOEXCEPT_SPECIFIER, const Extra&... extra) { + template + cpp_function(Return (Class::*f)(Arg...) const, const Extra&... extra) { initialize([f](const Class *c, Arg... args) -> Return { return (c->*f)(args...); }, - (Return (*)(const Class *, Arg ...) PYBIND11_NOEXCEPT_SPECIFIER) nullptr, extra...); + (Return (*)(const Class *, Arg ...)) nullptr, extra...); } /// Return the function name @@ -80,8 +81,8 @@ protected: } /// Special internal constructor for functors, lambda functions, etc. - template - void initialize(Func &&f, Return (*)(Args...) PYBIND11_NOEXCEPT_SPECIFIER, const Extra&... extra) { + template + void initialize(Func &&f, Return (*)(Args...), const Extra&... extra) { struct capture { typename std::remove_reference::type f; }; @@ -162,7 +163,7 @@ protected: if (cast_in::has_kwargs) rec->has_kwargs = true; /* Stash some additional information used by an important optimization in 'functional.h' */ - using FunctionType = Return (*)(Args...) PYBIND11_NOEXCEPT_SPECIFIER; + using FunctionType = Return (*)(Args...); constexpr bool is_function_ptr = std::is_convertible::value && sizeof(capture) == sizeof(void *);