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:
Robert Haschke
2021-03-17 02:10:12 +01:00
committed by GitHub
parent 469792032a
commit 784092dfd2
3 changed files with 80 additions and 0 deletions

View File

@@ -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>;