1010#pragma once
1111
1212#include " class.h"
13- #include " smart_holder_sfinae_hooks_only .h"
13+ #include " using_smart_holder .h"
1414
1515PYBIND11_NAMESPACE_BEGIN (PYBIND11_NAMESPACE)
1616
@@ -156,9 +156,7 @@ void construct(value_and_holder &v_h, Alias<Class> *alias_ptr, bool) {
156156// holder. This also handles types like std::shared_ptr<T> and std::unique_ptr<T> where T is a
157157// derived type (through those holder's implicit conversion from derived class holder
158158// constructors).
159- template <typename Class,
160- detail::enable_if_t <!detail::type_uses_smart_holder_type_caster<Cpp<Class>>::value, int >
161- = 0 >
159+ template <typename Class, detail::enable_if_t <!is_smart_holder<Holder<Class>>::value, int > = 0 >
162160void construct (value_and_holder &v_h, Holder<Class> holder, bool need_alias) {
163161 PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100 (need_alias);
164162 auto *ptr = holder_helper<Holder<Class>>::get (holder);
@@ -200,10 +198,18 @@ void construct(value_and_holder &v_h, Alias<Class> &&result, bool) {
200198 v_h.value_ptr () = new Alias<Class>(std::move (result));
201199}
202200
201+ #ifdef PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
202+
203+ template <typename T, typename D>
204+ smart_holder init_smart_holder_from_unique_ptr (std::unique_ptr<T, D> &&unq_ptr,
205+ bool void_cast_raw_ptr) {
206+ void *void_ptr = void_cast_raw_ptr ? static_cast <void *>(unq_ptr.get ()) : nullptr ;
207+ return smart_holder::from_unique_ptr (std::move (unq_ptr), void_ptr);
208+ }
209+
203210template <typename Class,
204211 typename D = std::default_delete<Cpp<Class>>,
205- detail::enable_if_t <detail::type_uses_smart_holder_type_caster<Cpp<Class>>::value, int >
206- = 0 >
212+ detail::enable_if_t <is_smart_holder<Holder<Class>>::value, int > = 0 >
207213void construct (value_and_holder &v_h, std::unique_ptr<Cpp<Class>, D> &&unq_ptr, bool need_alias) {
208214 PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100 (need_alias);
209215 auto *ptr = unq_ptr.get ();
@@ -217,30 +223,27 @@ void construct(value_and_holder &v_h, std::unique_ptr<Cpp<Class>, D> &&unq_ptr,
217223 // trampoline Python object alive. For types that don't inherit from enable_shared_from_this
218224 // it does not matter if void_cast_raw_ptr is true or false, therefore it's not necessary
219225 // to also inspect the type.
220- auto smhldr = type_caster<Cpp<Class>>:: smart_holder_from_unique_ptr (
226+ auto smhldr = init_smart_holder_from_unique_ptr (
221227 std::move (unq_ptr), /* void_cast_raw_ptr*/ Class::has_alias && is_alias<Class>(ptr));
222228 v_h.value_ptr () = ptr;
223229 v_h.type ->init_instance (v_h.inst , &smhldr);
224230}
225231
226232template <typename Class,
227233 typename D = std::default_delete<Alias<Class>>,
228- detail::enable_if_t <detail::type_uses_smart_holder_type_caster<Alias<Class>>::value, int >
229- = 0 >
234+ detail::enable_if_t <is_smart_holder<Holder<Class>>::value, int > = 0 >
230235void construct (value_and_holder &v_h,
231236 std::unique_ptr<Alias<Class>, D> &&unq_ptr,
232237 bool /* need_alias*/ ) {
233238 auto *ptr = unq_ptr.get ();
234239 no_nullptr (ptr);
235- auto smhldr = type_caster<Alias<Class>>:: smart_holder_from_unique_ptr (
236- std::move (unq_ptr), /* void_cast_raw_ptr*/ true );
240+ auto smhldr
241+ = init_smart_holder_from_unique_ptr ( std::move (unq_ptr), /* void_cast_raw_ptr*/ true );
237242 v_h.value_ptr () = ptr;
238243 v_h.type ->init_instance (v_h.inst , &smhldr);
239244}
240245
241- template <typename Class,
242- detail::enable_if_t <detail::type_uses_smart_holder_type_caster<Cpp<Class>>::value, int >
243- = 0 >
246+ template <typename Class, detail::enable_if_t <is_smart_holder<Holder<Class>>::value, int > = 0 >
244247void construct (value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, bool need_alias) {
245248 PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100 (need_alias);
246249 auto *ptr = shd_ptr.get ();
@@ -249,24 +252,24 @@ void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, boo
249252 throw type_error (" pybind11::init(): construction failed: returned std::shared_ptr pointee "
250253 " is not an alias instance" );
251254 }
252- auto smhldr = type_caster<Cpp<Class>>:: smart_holder_from_shared_ptr (shd_ptr);
255+ auto smhldr = smart_holder::from_shared_ptr (shd_ptr);
253256 v_h.value_ptr () = ptr;
254257 v_h.type ->init_instance (v_h.inst , &smhldr);
255258}
256259
257- template <typename Class,
258- detail::enable_if_t <detail::type_uses_smart_holder_type_caster<Alias<Class>>::value, int >
259- = 0 >
260+ template <typename Class, detail::enable_if_t <is_smart_holder<Holder<Class>>::value, int > = 0 >
260261void construct (value_and_holder &v_h,
261262 std::shared_ptr<Alias<Class>> &&shd_ptr,
262263 bool /* need_alias*/ ) {
263264 auto *ptr = shd_ptr.get ();
264265 no_nullptr (ptr);
265- auto smhldr = type_caster<Alias<Class>>:: smart_holder_from_shared_ptr (shd_ptr);
266+ auto smhldr = smart_holder::from_shared_ptr (shd_ptr);
266267 v_h.value_ptr () = ptr;
267268 v_h.type ->init_instance (v_h.inst , &smhldr);
268269}
269270
271+ #endif // PYBIND11_HAVE_INTERNALS_WITH_SMART_HOLDER_SUPPORT
272+
270273// Implementing class for py::init<...>()
271274template <typename ... Args>
272275struct constructor {
0 commit comments