Skip to content

Commit

Permalink
PYBIND11_HAVE_HOLDER_CASTER_WITH_SMART_HOLDER_SUPPORT
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Jul 13, 2024
1 parent 092d236 commit 6fa0a2e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -835,9 +835,18 @@ struct copyable_holder_caster : public type_caster_base<type> {
holder_type holder;
};

#define PYBIND11_HAVE_HOLDER_CASTER_WITH_SMART_HOLDER_SUPPORT

template <typename, typename SFINAE = void>
struct copyable_holder_caster_shared_ptr_with_smart_holder_support_enabled : std::true_type {};

// BAKEIN_WIP
template <typename type>
struct copyable_holder_caster<type, std::shared_ptr<type>> : public type_caster_base<type> {
struct copyable_holder_caster<
type,
std::shared_ptr<type>,
enable_if_t<copyable_holder_caster_shared_ptr_with_smart_holder_support_enabled<type>::value>>
: public type_caster_base<type> {
public:
using base = type_caster_base<type>;
static_assert(std::is_base_of<base, type_caster<type>>::value,
Expand Down Expand Up @@ -983,9 +992,15 @@ struct move_only_holder_caster {
static constexpr auto name = type_caster_base<type>::name;
};

template <typename, typename SFINAE = void>
struct move_only_holder_caster_unique_ptr_with_smart_holder_support_enabled : std::true_type {};

// BAKEIN_WIP
template <typename type, typename deleter>
struct move_only_holder_caster<type, std::unique_ptr<type, deleter>>
struct move_only_holder_caster<
type,
std::unique_ptr<type, deleter>,
enable_if_t<move_only_holder_caster_unique_ptr_with_smart_holder_support_enabled<type>::value>>
: public type_caster_base<type> {
public:
using base = type_caster_base<type>;
Expand Down

0 comments on commit 6fa0a2e

Please sign in to comment.