Skip to content

Commit f130cdd

Browse files
committed
Reduce move constructions
1 parent f93d0f0 commit f130cdd

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

include/pybind11/cast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ template <typename T> using cast_op_type_for_moving =
783783
template <typename T> using cast_op_type_for_byvalue =
784784
conditional_t<std::is_copy_constructible<intrinsic_t<T>>::value,
785785
typename std::add_lvalue_reference<intrinsic_t<T>>::type,
786-
cast_op_type_for_moving<T> >;
786+
typename std::add_rvalue_reference<intrinsic_t<T>>::type >;
787787

788788
/**
789789
* Determine suitable casting operator for movable types.

tests/test_copy_move.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ static_assert(std::is_same<movable_cast_op_type<MoveOrCopyInt&&>, MoveOrCopyInt>
8080
static_assert(std::is_same<movable_cast_op_type<MoveOnlyInt&&>, MoveOnlyInt>::value, "requesting move semantics");
8181
static_assert(std::is_same<movable_cast_op_type<CopyOnlyInt&&>, CopyOnlyInt>::value, "requesting move semantics");
8282

83-
// casting type for plain arguments is chose to yield copy semantics by default, but move semantics for move-only types
83+
// casting type for by-value arguments is chosen to yield copy semantics by default, but move semantics for move-only types
8484
static_assert(std::is_same<movable_cast_op_type<MoveOrCopyInt>, MoveOrCopyInt&>::value, "default to copy semantics");
85-
static_assert(std::is_same<movable_cast_op_type<MoveOnlyInt>, MoveOnlyInt>::value, "only move semantics supported");
85+
static_assert(std::is_same<movable_cast_op_type<MoveOnlyInt>, MoveOnlyInt&&>::value, "only move semantics supported");
8686
static_assert(std::is_same<movable_cast_op_type<CopyOnlyInt>, CopyOnlyInt&>::value, "copy semantics");
8787

8888
template <> struct type_caster<MoveOnlyInt> {

tests/test_copy_move.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_move_and_copy_loads():
6262

6363
assert c_m.copy_assignments + c_m.copy_constructions == 0
6464
assert c_m.move_assignments == 6
65-
assert c_m.move_constructions == 14
65+
assert c_m.move_constructions == 9
6666
assert c_mc.copy_assignments == 0
6767
assert c_mc.copy_constructions == 1
6868
assert c_mc.move_assignments == 6
@@ -123,7 +123,7 @@ def test_move_and_copy_load_optional():
123123

124124
assert c_m.copy_assignments + c_m.copy_constructions == 0
125125
assert c_m.move_assignments == 2
126-
assert c_m.move_constructions == 7
126+
assert c_m.move_constructions == 6
127127
assert c_mc.copy_assignments == 0
128128
assert c_mc.copy_constructions == 1
129129
assert c_mc.move_assignments == 3

0 commit comments

Comments
 (0)