[Bf-blender-cvs] [97ecf230694] functions: ArrayRef.copy_from

Jacques Lucke noreply at git.blender.org
Mon Jun 10 12:05:46 CEST 2019


Commit: 97ecf2306942d2ad7262f3f77246fa87bc66cc1a
Author: Jacques Lucke
Date:   Mon Jun 10 12:03:29 2019 +0200
Branches: functions
https://developer.blender.org/rB97ecf2306942d2ad7262f3f77246fa87bc66cc1a

ArrayRef.copy_from

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

M	source/blender/blenlib/BLI_array_ref.hpp
M	tests/gtests/blenlib/BLI_array_ref_test.cc

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

diff --git a/source/blender/blenlib/BLI_array_ref.hpp b/source/blender/blenlib/BLI_array_ref.hpp
index 317eff3164c..1f182d7e5ec 100644
--- a/source/blender/blenlib/BLI_array_ref.hpp
+++ b/source/blender/blenlib/BLI_array_ref.hpp
@@ -85,6 +85,17 @@ template<typename T> class ArrayRef {
     std::fill_n(m_start, m_size, element);
   }
 
+  void copy_from(const T *ptr)
+  {
+    std::copy_n(ptr, m_size, m_start);
+  }
+
+  void copy_from(ArrayRef<T> other)
+  {
+    BLI_assert(this->size() == other.size());
+    this->copy_from(other.begin());
+  }
+
   T *begin() const
   {
     return m_start;
diff --git a/tests/gtests/blenlib/BLI_array_ref_test.cc b/tests/gtests/blenlib/BLI_array_ref_test.cc
index df4e45fa46f..6af0b26659c 100644
--- a/tests/gtests/blenlib/BLI_array_ref_test.cc
+++ b/tests/gtests/blenlib/BLI_array_ref_test.cc
@@ -177,3 +177,16 @@ TEST(array_ref, Fill)
   EXPECT_EQ(a[3], 1);
   EXPECT_EQ(a[4], 1);
 }
+
+TEST(array_ref, CopyFrom)
+{
+  std::array<int, 3> a = {3, 4, 5};
+  IntArrayRef a_ref(a);
+  EXPECT_EQ(a[0], 3);
+  EXPECT_EQ(a[1], 4);
+  EXPECT_EQ(a[2], 5);
+  a_ref.copy_from({1, 2, 3});
+  EXPECT_EQ(a[0], 1);
+  EXPECT_EQ(a[1], 2);
+  EXPECT_EQ(a[2], 3);
+}



More information about the Bf-blender-cvs mailing list