mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-24 14:55:01 +00:00
Missing cast from const unique_ptr& (#2904)
* Add roundtrip tests for unique_ptr * Implementation for casting from const std::unique_ptr& ... forwarding to smart_holder_type_caster<T>::cast(T*)
This commit is contained in:
@@ -716,6 +716,15 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
|
||||
|
||||
return inst.release();
|
||||
}
|
||||
static handle cast(const std::unique_ptr<T, D> &src, return_value_policy policy, handle parent) {
|
||||
if (!src)
|
||||
return none().release();
|
||||
if (policy == return_value_policy::automatic)
|
||||
policy = return_value_policy::reference_internal;
|
||||
if (policy != return_value_policy::reference_internal)
|
||||
throw cast_error("Invalid return_value_policy for unique_ptr&");
|
||||
return smart_holder_type_caster<T>::cast(src.get(), policy, parent);
|
||||
}
|
||||
|
||||
template <typename>
|
||||
using cast_op_type = std::unique_ptr<T, D>;
|
||||
|
||||
Reference in New Issue
Block a user