[Bf-blender-cvs] [57cb7849faf] functions: construct SmallStack from array

Jacques Lucke noreply at git.blender.org
Fri Jul 5 17:38:51 CEST 2019


Commit: 57cb7849faf96935bfae05ccea0352c6948dd599
Author: Jacques Lucke
Date:   Fri Jul 5 15:03:48 2019 +0200
Branches: functions
https://developer.blender.org/rB57cb7849faf96935bfae05ccea0352c6948dd599

construct SmallStack from array

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

M	source/blender/blenlib/BLI_small_stack.hpp
M	tests/gtests/blenlib/BLI_small_stack_test.cc

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

diff --git a/source/blender/blenlib/BLI_small_stack.hpp b/source/blender/blenlib/BLI_small_stack.hpp
index d2f0587a139..31555dbcd43 100644
--- a/source/blender/blenlib/BLI_small_stack.hpp
+++ b/source/blender/blenlib/BLI_small_stack.hpp
@@ -34,6 +34,14 @@ template<typename T, uint N = 4> class SmallStack {
  public:
   SmallStack() = default;
 
+  /**
+   * Construct a stack from an array ref. The elements will be pushed in the same order they are in
+   * the array.
+   */
+  SmallStack(ArrayRef<T> values) : m_elements(values)
+  {
+  }
+
   /**
    * Return the number of elements in the stack.
    */
diff --git a/tests/gtests/blenlib/BLI_small_stack_test.cc b/tests/gtests/blenlib/BLI_small_stack_test.cc
index a9ba2cfa31f..a50ed4a7af4 100644
--- a/tests/gtests/blenlib/BLI_small_stack_test.cc
+++ b/tests/gtests/blenlib/BLI_small_stack_test.cc
@@ -10,6 +10,17 @@ TEST(small_stack, DefaultConstructor)
   EXPECT_TRUE(stack.empty());
 }
 
+TEST(small_stack, ArrayRefConstructor)
+{
+  std::array<int, 3> array = {4, 7, 2};
+  IntStack stack(array);
+  EXPECT_EQ(stack.size(), 3);
+  EXPECT_EQ(stack.pop(), 2);
+  EXPECT_EQ(stack.pop(), 7);
+  EXPECT_EQ(stack.pop(), 4);
+  EXPECT_TRUE(stack.empty());
+}
+
 TEST(small_stack, Push)
 {
   IntStack stack;



More information about the Bf-blender-cvs mailing list