Skip to content

Commit c1c2590

Browse files
committed
Implementation for casting from const std::unique_ptr&
... forwarding to type_caster_base<T>::cast(T*)
1 parent 3b66075 commit c1c2590

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
@@ -698,6 +698,15 @@ struct smart_holder_type_caster<std::unique_ptr<T, D>> : smart_holder_type_caste
698698

699699
return inst.release();
700700
}
701+
static handle cast(const std::unique_ptr<T, D> &src, return_value_policy policy, handle parent) {
702+
if (!src)
703+
return none().release();
704+
if (policy == return_value_policy::automatic)
705+
policy = return_value_policy::reference_internal;
706+
if (policy != return_value_policy::reference_internal)
707+
throw cast_error("Invalid return_value_policy for unique_ptr&");
708+
return type_caster_base<T>::cast(src.get(), policy, parent);
709+
}
701710

702711
template <typename>
703712
using cast_op_type = std::unique_ptr<T, D>;

0 commit comments

Comments
 (0)