[Bf-blender-cvs] [bc218feff12] functions: append n times function for vector adaptor
Jacques Lucke
noreply at git.blender.org
Wed Aug 28 18:01:20 CEST 2019
Commit: bc218feff12c726bd390a312759a42df72ccb47b
Author: Jacques Lucke
Date: Wed Aug 28 14:23:10 2019 +0200
Branches: functions
https://developer.blender.org/rBbc218feff12c726bd390a312759a42df72ccb47b
append n times function for vector adaptor
===================================================================
M source/blender/blenlib/BLI_vector_adaptor.hpp
M tests/gtests/blenlib/BLI_vector_adaptor_test.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_vector_adaptor.hpp b/source/blender/blenlib/BLI_vector_adaptor.hpp
index 5c85cb0b0f8..a1e316f30fc 100644
--- a/source/blender/blenlib/BLI_vector_adaptor.hpp
+++ b/source/blender/blenlib/BLI_vector_adaptor.hpp
@@ -96,6 +96,13 @@ template<typename T> class VectorAdaptor {
m_end += 1;
}
+ void append_n_times(const T &value, uint n)
+ {
+ BLI_assert(this->size() + n <= m_capacity);
+ uninitialized_fill_n(m_end, n, value);
+ m_end += n;
+ }
+
/**
* Insert multiple elements at the end of the vector.
* Asserts, when the capacity is exceeded.
diff --git a/tests/gtests/blenlib/BLI_vector_adaptor_test.cc b/tests/gtests/blenlib/BLI_vector_adaptor_test.cc
index b100b5a5d97..f5ceec504db 100644
--- a/tests/gtests/blenlib/BLI_vector_adaptor_test.cc
+++ b/tests/gtests/blenlib/BLI_vector_adaptor_test.cc
@@ -85,3 +85,17 @@ TEST(vector_adaptor, Extend)
EXPECT_EQ(vec[2], 2);
EXPECT_EQ(vec[3], 5);
}
+
+TEST(vector_adaptor, AppendNTimes)
+{
+ int array[6];
+ IntVectorAdaptor vec(array);
+ vec.append_n_times(10, 2);
+ vec.append_n_times(5, 3);
+ EXPECT_EQ(vec.size(), 5);
+ EXPECT_EQ(vec[0], 10);
+ EXPECT_EQ(vec[1], 10);
+ EXPECT_EQ(vec[2], 5);
+ EXPECT_EQ(vec[3], 5);
+ EXPECT_EQ(vec[4], 5);
+}
More information about the Bf-blender-cvs
mailing list