Skip to content

Commit

Permalink
Two more tests to make sure I understand
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentHouliston committed Dec 27, 2024
1 parent bc8841e commit bf8ac58
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/tests/util/moving.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ void perfect_forwarding(T&& v) {
std::vector<int> v2 = std::forward<T>(v);
}

template <typename T>
void perfect_forwarding_to_assign(T&& v) {
assign(std::forward<T>(v));
}

template <typename T>
void perfect_forwarding_to_assign_with_move(T&& v) {
assign_with_move(std::forward<T>(v));
}

} // namespace

SCENARIO("Testing how rvalues are handled") {
Expand Down Expand Up @@ -82,5 +92,21 @@ SCENARIO("Testing how rvalues are handled") {
REQUIRE(v1 == std::vector<int>{0, 1});
}
}

WHEN("moving it to a function that assigns with perfect forwarding") {
perfect_forwarding_to_assign(std::move(v1));
THEN("the vector is not empty") {
REQUIRE(v1 == std::vector<int>{0, 1});
}
}

WHEN(
"moving it to a function as an rvalue and assigns it to a new vector with std::move with perfect "
"forwarding") {
perfect_forwarding_to_assign_with_move(std::move(v1));
THEN("the vector is empty") {
REQUIRE(v1 == std::vector<int>{});
}
}
}
}

0 comments on commit bf8ac58

Please sign in to comment.