From 6fa0a2e43928cf69becc8be316a4bcedb894f127 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Fri, 12 Jul 2024 22:55:23 -0700 Subject: [PATCH] PYBIND11_HAVE_HOLDER_CASTER_WITH_SMART_HOLDER_SUPPORT Introduce two helper types: * copyable_holder_caster_shared_ptr_with_smart_holder_support_enabled * move_only_holder_caster_unique_ptr_with_smart_holder_support_enabled --- include/pybind11/cast.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 86cc0e507..7cf2a3117 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -835,9 +835,18 @@ protected: holder_type holder; }; +#define PYBIND11_HAVE_HOLDER_CASTER_WITH_SMART_HOLDER_SUPPORT + +template +struct copyable_holder_caster_shared_ptr_with_smart_holder_support_enabled : std::true_type {}; + // BAKEIN_WIP template -struct copyable_holder_caster> : public type_caster_base { +struct copyable_holder_caster< + type, + std::shared_ptr, + enable_if_t::value>> + : public type_caster_base { public: using base = type_caster_base; static_assert(std::is_base_of>::value, @@ -983,9 +992,15 @@ struct move_only_holder_caster { static constexpr auto name = type_caster_base::name; }; +template +struct move_only_holder_caster_unique_ptr_with_smart_holder_support_enabled : std::true_type {}; + // BAKEIN_WIP template -struct move_only_holder_caster> +struct move_only_holder_caster< + type, + std::unique_ptr, + enable_if_t::value>> : public type_caster_base { public: using base = type_caster_base;