Skip to content

Commit

Permalink
Systematically replacing detail::enable_if_t<...smart_holder...> wi…
Browse files Browse the repository at this point in the history
…th `typename std::enable_if<...smart_holder...>::type`. Attempt to work around MSVC 2015 issues, to be tested via GitHub CI. The idea for this change originates from this comment: #1616 (comment)
  • Loading branch information
rwgk committed Feb 12, 2021
1 parent 7aa604d commit 5d4b689
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion include/pybind11/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -2459,7 +2459,7 @@ struct is_smart_holder_type_caster : std::false_type {};
template <typename T>
struct is_smart_holder_type_caster<
T,
enable_if_t<type_caster<T>::is_smart_holder_type_caster::value, void>> : std::true_type {};
typename std::enable_if<type_caster<T>::is_smart_holder_type_caster::value, void>::type> : std::true_type {};

template <typename T>
inline bool check_is_smart_holder_type_caster() {
Expand Down
6 changes: 3 additions & 3 deletions include/pybind11/detail/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void construct(value_and_holder &v_h, Alias<Class> *alias_ptr, bool) {
// holder. This also handles types like std::shared_ptr<T> and std::unique_ptr<T> where T is a
// derived type (through those holder's implicit conversion from derived class holder constructors).
template <typename Class,
detail::enable_if_t<!detail::is_smart_holder_type_caster<Cpp<Class>>::value, int> = 0>
typename std::enable_if<!detail::is_smart_holder_type_caster<Cpp<Class>>::value, int>::type = 0>
void construct(value_and_holder &v_h, Holder<Class> holder, bool need_alias) {
auto *ptr = holder_helper<Holder<Class>>::get(holder);
no_nullptr(ptr);
Expand Down Expand Up @@ -172,7 +172,7 @@ void construct(value_and_holder &v_h, Alias<Class> &&result, bool) {
//DETAIL/SMART_HOLDER_INIT_H/BEGIN/////////////////////////////////////////////////////////////////

template <typename Class, typename D = std::default_delete<Cpp<Class>>,
detail::enable_if_t<detail::is_smart_holder_type_caster<Cpp<Class>>::value, int> = 0>
typename std::enable_if<detail::is_smart_holder_type_caster<Cpp<Class>>::value, int>::type = 0>
void construct(value_and_holder &v_h, std::unique_ptr<Cpp<Class>, D> &&unq_ptr, bool need_alias) {
auto *ptr = unq_ptr.get();
no_nullptr(ptr);
Expand All @@ -188,7 +188,7 @@ void construct(value_and_holder &v_h, std::unique_ptr<Cpp<Class>, D> &&unq_ptr,
}

template <typename Class,
detail::enable_if_t<detail::is_smart_holder_type_caster<Cpp<Class>>::value, int> = 0>
typename std::enable_if<detail::is_smart_holder_type_caster<Cpp<Class>>::value, int>::type = 0>
void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, bool need_alias) {
auto *ptr = shd_ptr.get();
no_nullptr(ptr);
Expand Down
8 changes: 4 additions & 4 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1544,14 +1544,14 @@ class class_ : public detail::generic_type {
private:
template <
typename T = type,
detail::enable_if_t<!detail::is_smart_holder_type_caster<T>::value, int> = 0>
typename std::enable_if<!detail::is_smart_holder_type_caster<T>::value, int>::type = 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::is_smart_holder_type_caster<T>::value, int> = 0>
typename std::enable_if<detail::is_smart_holder_type_caster<T>::value, int>::type = 0>
void generic_type_initialize(const detail::type_record &record) {
generic_type::initialize(record, detail::type_caster<T>::get_local_load_function_ptr());
}
Expand Down Expand Up @@ -1602,7 +1602,7 @@ class class_ : public detail::generic_type {
/// `.owned`, a new holder will be constructed to manage the value pointer.
template <
typename T = type,
detail::enable_if_t<!detail::is_smart_holder_type_caster<T>::value, int> = 0>
typename std::enable_if<!detail::is_smart_holder_type_caster<T>::value, int>::type = 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()) {
Expand All @@ -1614,7 +1614,7 @@ class class_ : public detail::generic_type {

template <
typename T = type,
detail::enable_if_t<detail::is_smart_holder_type_caster<T>::value, int> = 0>
typename std::enable_if<detail::is_smart_holder_type_caster<T>::value, int>::type = 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);
}
Expand Down

0 comments on commit 5d4b689

Please sign in to comment.