mirror of
https://github.com/pybind/pybind11.git
synced 2025-01-31 23:30:30 +00:00
Introduce type_caster_base<>::unique_ptr_to_python()
This commit is contained in:
parent
5518e01562
commit
6ff547e18a
@ -932,8 +932,7 @@ struct move_only_holder_caster<type, std::unique_ptr<type, deleter>> {
|
||||
"Holder classes are only supported for custom types");
|
||||
|
||||
static handle cast(std::unique_ptr<type, deleter> &&src, return_value_policy, handle) {
|
||||
auto *ptr = src.get();
|
||||
return type_caster_base<type>::cast_holder(ptr, std::addressof(src));
|
||||
return type_caster_base<type>::unique_ptr_to_python(std::move(src));
|
||||
}
|
||||
static constexpr auto name = type_caster_base<type>::name;
|
||||
};
|
||||
|
@ -1160,6 +1160,22 @@ public:
|
||||
holder);
|
||||
}
|
||||
|
||||
template <typename T, typename D>
|
||||
static handle unique_ptr_to_python(std::unique_ptr<T, D> &&unq_ptr) {
|
||||
auto *src = unq_ptr.get();
|
||||
auto st = src_and_type(src);
|
||||
if (st.second->default_holder) {
|
||||
throw std::runtime_error("BAKEIN_WIP");
|
||||
}
|
||||
return type_caster_generic::cast(st.first,
|
||||
return_value_policy::take_ownership,
|
||||
{},
|
||||
st.second,
|
||||
nullptr,
|
||||
nullptr,
|
||||
std::addressof(unq_ptr));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
using cast_op_type = detail::cast_op_type<T>;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user