[Bf-blender-cvs] [c76ed1781b9] functions: method to fill an ArrayRef
Jacques Lucke
noreply at git.blender.org
Sat Jun 8 14:21:57 CEST 2019
Commit: c76ed1781b9a7c0985c810b69ee24419a019bc3b
Author: Jacques Lucke
Date: Sat Jun 8 13:28:35 2019 +0200
Branches: functions
https://developer.blender.org/rBc76ed1781b9a7c0985c810b69ee24419a019bc3b
method to fill an ArrayRef
===================================================================
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 7f6c11a0808..c30016b2a03 100644
--- a/source/blender/blenlib/BLI_array_ref.hpp
+++ b/source/blender/blenlib/BLI_array_ref.hpp
@@ -72,6 +72,11 @@ template<typename T> class ArrayRef {
return this->slice(0, this->size() - n);
}
+ void fill(const T &element)
+ {
+ std::fill_n(m_start, m_size, element);
+ }
+
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 c9a764ee9f6..4ff819bf797 100644
--- a/tests/gtests/blenlib/BLI_array_ref_test.cc
+++ b/tests/gtests/blenlib/BLI_array_ref_test.cc
@@ -147,3 +147,15 @@ TEST(array_ref, FromArray)
EXPECT_EQ(a_ref[0], 5);
EXPECT_EQ(a_ref[1], 6);
}
+
+TEST(array_ref, Fill)
+{
+ std::array<int, 5> a = {4, 5, 6, 7, 8};
+ IntArrayRef a_ref(a);
+ a_ref.fill(1);
+ EXPECT_EQ(a[0], 1);
+ EXPECT_EQ(a[1], 1);
+ EXPECT_EQ(a[2], 1);
+ EXPECT_EQ(a[3], 1);
+ EXPECT_EQ(a[4], 1);
+}
More information about the Bf-blender-cvs
mailing list