Skip to content

Commit 4c76ada

Browse files
committed
Implementation for casting from const std::unique_ptr&
... forwarding to smart_holder_type_caster<T>::cast(T*)
1 parent 6812cea commit 4c76ada

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

include/pybind11/detail/smart_holder_type_casters.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,15 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
716716

717717
return inst.release();
718718
}
719+
static handle cast(const std::unique_ptr<T, D> &src, return_value_policy policy, handle parent) {
720+
if (!src)
721+
return none().release();
722+
if (policy == return_value_policy::automatic)
723+
policy = return_value_policy::reference_internal;
724+
if (policy != return_value_policy::reference_internal)
725+
throw cast_error("Invalid return_value_policy for unique_ptr&");
726+
return smart_holder_type_caster<T>::cast(src.get(), policy, parent);
727+
}
719728

720729
template <typename>
721730
using cast_op_type = std::unique_ptr<T, D>;

0 commit comments

Comments
 (0)