Skip to content

Commit

Permalink
clean out smart_holder_type_casters-related code
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Jul 31, 2024
1 parent e6c74df commit 194d3d9
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class type_caster_enum_type {
if (native_enum) {
return native_enum(static_cast<Underlying>(src)).release();
}
return type_caster_for_class_<EnumType>::cast(
return type_caster_base<EnumType>::cast(
std::forward<SrcType>(src),
// Fixes https://github.com/pybind/pybind11/pull/3643#issuecomment-1022987818:
return_value_policy::copy,
Expand All @@ -91,7 +91,7 @@ class type_caster_enum_type {
return true;
}
if (!pybind11_enum_) {
pybind11_enum_.reset(new type_caster_for_class_<EnumType>());
pybind11_enum_.reset(new type_caster_base<EnumType>());
}
return pybind11_enum_->load(src, convert);
}
Expand All @@ -116,7 +116,7 @@ class type_caster_enum_type {
}

private:
std::unique_ptr<type_caster_for_class_<EnumType>> pybind11_enum_;
std::unique_ptr<type_caster_base<EnumType>> pybind11_enum_;
EnumType value;
};

Expand All @@ -133,27 +133,6 @@ template <typename EnumType>
class type_caster<EnumType, detail::enable_if_t<type_uses_type_caster_enum_type<EnumType>::value>>
: public type_caster_enum_type<EnumType> {};

template <typename T>
struct type_uses_smart_holder_type_caster {
static constexpr bool value
= std::is_base_of<smart_holder_type_caster_base_tag, make_caster<T>>::value
#ifdef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
|| type_uses_type_caster_enum_type<T>::value
#endif
;
};

template <typename T, typename SFINAE = void>
struct type_caster_classh_enum_aware : type_caster<T> {};

#ifdef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
template <typename EnumType>
struct type_caster_classh_enum_aware<
EnumType,
detail::enable_if_t<type_uses_type_caster_enum_type<EnumType>::value>>
: type_caster_for_class_<EnumType> {};
#endif

template <typename T, detail::enable_if_t<std::is_enum<T>::value, int> = 0>
bool isinstance_native_enum_impl(handle obj, const std::type_info &tp) {
handle native_enum = global_internals_native_enum_type_map_get_item(tp);
Expand Down

0 comments on commit 194d3d9

Please sign in to comment.