diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 2ae25c2ebf..a82f3d8230 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -869,17 +869,27 @@ struct always_construct_holder { }; /// Create a specialization for custom holder types (silently ignores std::shared_ptr) -#define PYBIND11_DECLARE_HOLDER_TYPE(type, holder_type, ...) \ +#define PYBIND11_DECLARE_HOLDER_TYPE_PART1(type, ...) \ PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE) \ namespace detail { \ template \ - struct always_construct_holder : always_construct_holder { \ - }; \ + struct always_construct_holder<__VA_ARGS__> : always_construct_holder < +#define PYBIND11_DECLARE_HOLDER_TYPE_PART2(type, ...) \ + >{}; \ template \ - class type_caster::value>> \ - : public type_caster_holder {}; \ + class type_caster<__VA_ARGS__, enable_if_t::value>> \ + : public type_caster_holder {}; \ } \ PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE) +#if defined(PYBIND11_CPP20) +# define PYBIND11_DECLARE_HOLDER_TYPE(type, holder_type, ...) \ + PYBIND11_DECLARE_HOLDER_TYPE_PART1(type, holder_type) \ + void __VA_OPT__(, ) __VA_ARGS__ PYBIND11_DECLARE_HOLDER_TYPE_PART2(type, holder_type) +#else +# define PYBIND11_DECLARE_HOLDER_TYPE(type, holder_type, ...) \ + PYBIND11_DECLARE_HOLDER_TYPE_PART1(type, holder_type) \ + void, ##__VA_ARGS__ PYBIND11_DECLARE_HOLDER_TYPE_PART2(type, holder_type) +#endif // PYBIND11_DECLARE_HOLDER_TYPE holder types: template