about summary refs log tree commit diff
path: root/absl/algorithm
diff options
context:
space:
mode:
Diffstat (limited to 'absl/algorithm')
-rw-r--r--absl/algorithm/container.h2
-rw-r--r--absl/algorithm/container_test.cc15
2 files changed, 16 insertions, 1 deletions
diff --git a/absl/algorithm/container.h b/absl/algorithm/container.h
index 6af8c09799e5..53ab15686c6e 100644
--- a/absl/algorithm/container.h
+++ b/absl/algorithm/container.h
@@ -494,7 +494,7 @@ BidirectionalIterator c_copy_backward(const C& src,
 // Container-based version of the <algorithm> `std::move()` function to move
 // a container's elements into an iterator.
 template <typename C, typename OutputIterator>
-OutputIterator c_move(C& src, OutputIterator dest) {
+OutputIterator c_move(C&& src, OutputIterator dest) {
   return std::move(container_algorithm_internal::c_begin(src),
                    container_algorithm_internal::c_end(src), dest);
 }
diff --git a/absl/algorithm/container_test.cc b/absl/algorithm/container_test.cc
index de66f14680f1..1502b17f8636 100644
--- a/absl/algorithm/container_test.cc
+++ b/absl/algorithm/container_test.cc
@@ -636,6 +636,21 @@ TEST(MutatingTest, Move) {
                                 Pointee(5)));
 }
 
+TEST(MutatingTest, MoveWithRvalue) {
+  auto MakeRValueSrc = [] {
+    std::vector<std::unique_ptr<int>> src;
+    src.emplace_back(absl::make_unique<int>(1));
+    src.emplace_back(absl::make_unique<int>(2));
+    src.emplace_back(absl::make_unique<int>(3));
+    return src;
+  };
+
+  std::vector<std::unique_ptr<int>> dest = MakeRValueSrc();
+  absl::c_move(MakeRValueSrc(), std::back_inserter(dest));
+  EXPECT_THAT(dest, ElementsAre(Pointee(1), Pointee(2), Pointee(3), Pointee(1),
+                                Pointee(2), Pointee(3)));
+}
+
 TEST(MutatingTest, SwapRanges) {
   std::vector<int> odds = {2, 4, 6};
   std::vector<int> evens = {1, 3, 5};