[Bf-blender-cvs] [fe697e5c1f1] functions: SmallSet.add_multiple_new

Jacques Lucke noreply at git.blender.org
Mon Jul 8 17:57:00 CEST 2019


Commit: fe697e5c1f1733939444489679367a0ff0a84b36
Author: Jacques Lucke
Date:   Mon Jul 8 13:30:08 2019 +0200
Branches: functions
https://developer.blender.org/rBfe697e5c1f1733939444489679367a0ff0a84b36

SmallSet.add_multiple_new

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

M	source/blender/blenlib/BLI_small_set.hpp
M	tests/gtests/blenlib/BLI_small_set_test.cc

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

diff --git a/source/blender/blenlib/BLI_small_set.hpp b/source/blender/blenlib/BLI_small_set.hpp
index 9d378bdc2f5..d9c650e85c5 100644
--- a/source/blender/blenlib/BLI_small_set.hpp
+++ b/source/blender/blenlib/BLI_small_set.hpp
@@ -115,6 +115,17 @@ template<typename T, uint N = 4> class SmallSet {
     }
   }
 
+  /**
+   * Insert multiple values in the set.
+   * Asserts when any of the values exists already.
+   */
+  void add_multiple_new(ArrayRef<T> values)
+  {
+    for (T &value : values) {
+      this->add_new(value);
+    }
+  }
+
   /**
    * Remove and return any value from the set.
    */
diff --git a/tests/gtests/blenlib/BLI_small_set_test.cc b/tests/gtests/blenlib/BLI_small_set_test.cc
index 13a910dc405..07c249ee786 100644
--- a/tests/gtests/blenlib/BLI_small_set_test.cc
+++ b/tests/gtests/blenlib/BLI_small_set_test.cc
@@ -146,9 +146,18 @@ TEST(small_set, AddMultiple)
   EXPECT_TRUE(a.contains(5));
   EXPECT_TRUE(a.contains(7));
   EXPECT_FALSE(a.contains(4));
-  a.add_multiple({2, 4});
+  a.add_multiple({2, 4, 7});
   EXPECT_TRUE(a.contains(4));
   EXPECT_TRUE(a.contains(2));
+  EXPECT_EQ(a.size(), 4);
+}
+
+TEST(small_set, AddMultipleNew)
+{
+  IntSet a;
+  a.add_multiple_new({5, 6});
+  EXPECT_TRUE(a.contains(5));
+  EXPECT_TRUE(a.contains(6));
 }
 
 TEST(small_set, ToSmallVector)



More information about the Bf-blender-cvs mailing list