[Bf-blender-cvs] [deb3d566a5a] master: BLI: fix Vector.prepend declaration

Jacques Lucke noreply at git.blender.org
Mon Dec 20 10:47:02 CET 2021


Commit: deb3d566a5ab3ee20e9e41bdb4835cd0f11928ed
Author: Jacques Lucke
Date:   Mon Dec 20 10:46:25 2021 +0100
Branches: master
https://developer.blender.org/rBdeb3d566a5ab3ee20e9e41bdb4835cd0f11928ed

BLI: fix Vector.prepend declaration

Using `&&` there was a typo. With `&&` the `prepend` method
could not be called with a const reference as argument.

===================================================================

M	source/blender/blenlib/BLI_vector.hh
M	source/blender/blenlib/tests/BLI_vector_test.cc

===================================================================

diff --git a/source/blender/blenlib/BLI_vector.hh b/source/blender/blenlib/BLI_vector.hh
index d2b94a6d8ef..4ac48f259cf 100644
--- a/source/blender/blenlib/BLI_vector.hh
+++ b/source/blender/blenlib/BLI_vector.hh
@@ -637,7 +637,7 @@ class Vector {
    * Insert values at the beginning of the vector. The has to move all the other elements, so it
    * has a linear running time.
    */
-  void prepend(const T &&value)
+  void prepend(const T &value)
   {
     this->insert(0, value);
   }
diff --git a/source/blender/blenlib/tests/BLI_vector_test.cc b/source/blender/blenlib/tests/BLI_vector_test.cc
index e8636168308..e9393a2b1e5 100644
--- a/source/blender/blenlib/tests/BLI_vector_test.cc
+++ b/source/blender/blenlib/tests/BLI_vector_test.cc
@@ -708,6 +708,17 @@ TEST(vector, Prepend)
   EXPECT_EQ_ARRAY(vec.data(), Span({7, 8, 1, 2, 3}).data(), 5);
 }
 
+TEST(vector, PrependString)
+{
+  std::string s = "test";
+  Vector<std::string> vec;
+  vec.prepend(s);
+  vec.prepend(std::move(s));
+  EXPECT_EQ(vec.size(), 2);
+  EXPECT_EQ(vec[0], "test");
+  EXPECT_EQ(vec[1], "test");
+}
+
 TEST(vector, ReverseIterator)
 {
   Vector<int> vec = {4, 5, 6, 7};



More information about the Bf-blender-cvs mailing list