Skip to content

Commit 7b795fe

Browse files
committed
Making rvp::move default for py::cast with rvalue reference
1 parent 8508572 commit 7b795fe

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/pybind11/cast.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -1608,9 +1608,11 @@ template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> =
16081608
object cast(T &&value, return_value_policy policy = return_value_policy::automatic_reference,
16091609
handle parent = handle()) {
16101610
if (policy == return_value_policy::automatic)
1611-
policy = std::is_pointer<T>::value ? return_value_policy::take_ownership : return_value_policy::copy;
1611+
policy = std::is_pointer<T>::value ? return_value_policy::take_ownership :
1612+
std::is_lvalue_reference<T>::value ? return_value_policy::copy : return_value_policy::move;
16121613
else if (policy == return_value_policy::automatic_reference)
1613-
policy = std::is_pointer<T>::value ? return_value_policy::reference : return_value_policy::copy;
1614+
policy = std::is_pointer<T>::value ? return_value_policy::reference :
1615+
std::is_lvalue_reference<T>::value ? return_value_policy::copy : return_value_policy::move;
16141616
return reinterpret_steal<object>(detail::make_caster<T>::cast(std::forward<T>(value), policy, parent));
16151617
}
16161618

0 commit comments

Comments
 (0)