Skip to content

Commit 8fe9412

Browse files
committed
use c++11 compatible code
1 parent 0318287 commit 8fe9412

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

include/pybind11/detail/init.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ void construct(value_and_holder &v_h, Holder<Class> holder, bool need_alias) {
167167
"is not an alias instance");
168168
}
169169

170-
v_h.value_ptr<std::remove_pointer_t<decltype(ptr)>>() = ptr;
170+
v_h.value_ptr<typename std::remove_pointer<decltype(ptr)>::type>() = ptr;
171171
v_h.type->init_instance(v_h.inst, &holder);
172172
}
173173

include/pybind11/detail/value_and_holder.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ struct value_and_holder {
3333

3434
template <typename V = void>
3535
V *&value_ptr() const {
36-
if constexpr (std::is_const_v<V>) {
37-
return reinterpret_cast<V *&>(const_cast<const void *&>(vh[0]));
38-
} else {
39-
return reinterpret_cast<V *&>(vh[0]);
40-
}
36+
return cast_void<V>(vh[0]);
4137
}
4238
// True if this `value_and_holder` has a non-null value pointer
4339
explicit operator bool() const { return value_ptr() != nullptr; }
@@ -76,6 +72,17 @@ struct value_and_holder {
7672
inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_instance_registered;
7773
}
7874
}
75+
76+
private:
77+
template <typename V, detail::enable_if_t<!std::is_const<V>::value, bool> = true>
78+
static V *&cast_void(void *&ptr) {
79+
return reinterpret_cast<V *&>(ptr);
80+
}
81+
82+
template <typename V, detail::enable_if_t<std::is_const<V>::value, bool> = true>
83+
static V *&cast_void(void *&ptr) {
84+
return reinterpret_cast<V *&>(const_cast<const void *&>(ptr));
85+
}
7986
};
8087

8188
// This is a semi-public API to check if the corresponding instance has been constructed with a

0 commit comments

Comments
 (0)