Giving up on idea to use legacy init_instance only if is_base_of<type_caster_generic, type_caster<T>. There are use cases in the wild that define both a custom type_caster and class_.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-01-28 21:01:37 -08:00
parent 149e332b3e
commit c9d73aaa43

View File

@ -1506,17 +1506,16 @@ public:
}
private:
template <typename T = type,
detail::enable_if_t<
std::is_base_of<detail::type_caster_generic, detail::type_caster<T>>::value,
int> = 0>
template <
typename T = type,
detail::enable_if_t<!detail::is_smart_holder_type_caster<T>::value, int> = 0>
void generic_type_initialize(const detail::type_record &record) {
generic_type::initialize(record, &detail::type_caster_generic::local_load);
}
template <
typename T = type,
detail::enable_if_t<detail::type_caster<T>::is_smart_holder_type_caster::value, int> = 0>
detail::enable_if_t<detail::is_smart_holder_type_caster<T>::value, int> = 0>
void generic_type_initialize(const detail::type_record &record) {
generic_type::initialize(record, detail::type_caster<T>::get_local_load_function_ptr());
}
@ -1565,10 +1564,9 @@ private:
/// instance. Should be called as soon as the `type` value_ptr is set for an instance. Takes an
/// optional pointer to an existing holder to use; if not specified and the instance is
/// `.owned`, a new holder will be constructed to manage the value pointer.
template <typename T = type,
detail::enable_if_t<
std::is_base_of<detail::type_caster_generic, detail::type_caster<T>>::value,
int> = 0>
template <
typename T = type,
detail::enable_if_t<!detail::is_smart_holder_type_caster<T>::value, int> = 0>
static void init_instance(detail::instance *inst, const void *holder_ptr) {
auto v_h = inst->get_value_and_holder(detail::get_type_info(typeid(type)));
if (!v_h.instance_registered()) {
@ -1580,7 +1578,7 @@ private:
template <
typename T = type,
detail::enable_if_t<detail::type_caster<T>::is_smart_holder_type_caster::value, int> = 0>
detail::enable_if_t<detail::is_smart_holder_type_caster<T>::value, int> = 0>
static void init_instance(detail::instance *inst, const void *holder_ptr) {
detail::type_caster<T>::template init_instance_for_type<type>(inst, holder_ptr);
}