Skip to content

Commit 2354071

Browse files
committed
Making rvp::move default for py::cast with rvalue reference
1 parent 882ba64 commit 2354071

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

include/pybind11/cast.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,9 +1670,11 @@ template <typename T, detail::enable_if_t<!detail::is_pyobject<T>::value, int> =
16701670
object cast(T &&value, return_value_policy policy = return_value_policy::automatic_reference,
16711671
handle parent = handle()) {
16721672
if (policy == return_value_policy::automatic)
1673-
policy = std::is_pointer<T>::value ? return_value_policy::take_ownership : return_value_policy::copy;
1673+
policy = std::is_pointer<T>::value ? return_value_policy::take_ownership :
1674+
std::is_lvalue_reference<T>::value ? return_value_policy::copy : return_value_policy::move;
16741675
else if (policy == return_value_policy::automatic_reference)
1675-
policy = std::is_pointer<T>::value ? return_value_policy::reference : return_value_policy::copy;
1676+
policy = std::is_pointer<T>::value ? return_value_policy::reference :
1677+
std::is_lvalue_reference<T>::value ? return_value_policy::copy : return_value_policy::move;
16761678
return reinterpret_steal<object>(detail::make_caster<T>::cast(std::forward<T>(value), policy, parent));
16771679
}
16781680

0 commit comments

Comments
 (0)