[Bf-blender-cvs] [5d08ae535a4] functions: Utility to convert SmallSet to SmallVector

Jacques Lucke noreply at git.blender.org
Tue Jun 18 12:39:06 CEST 2019


Commit: 5d08ae535a4de6497a660fcd45616eb302d12ab3
Author: Jacques Lucke
Date:   Tue Jun 18 12:03:15 2019 +0200
Branches: functions
https://developer.blender.org/rB5d08ae535a4de6497a660fcd45616eb302d12ab3

Utility to convert SmallSet to SmallVector

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

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 02942a2b029..cdd32e1a7f3 100644
--- a/source/blender/blenlib/BLI_small_set.hpp
+++ b/source/blender/blenlib/BLI_small_set.hpp
@@ -99,6 +99,11 @@ template<typename T, uint N = 4> class SmallSet {
     return m_elements[0];
   }
 
+  SmallVector<T> to_small_vector() const
+  {
+    return m_elements;
+  }
+
   static bool Disjoint(const SmallSet &a, const SmallSet &b)
   {
     return !SmallSet::Intersects(a, b);
diff --git a/tests/gtests/blenlib/BLI_small_set_test.cc b/tests/gtests/blenlib/BLI_small_set_test.cc
index 4118907dde2..13a910dc405 100644
--- a/tests/gtests/blenlib/BLI_small_set_test.cc
+++ b/tests/gtests/blenlib/BLI_small_set_test.cc
@@ -150,3 +150,13 @@ TEST(small_set, AddMultiple)
   EXPECT_TRUE(a.contains(4));
   EXPECT_TRUE(a.contains(2));
 }
+
+TEST(small_set, ToSmallVector)
+{
+  IntSet a = {5, 2, 8};
+  BLI::SmallVector<int> vec = a.to_small_vector();
+  EXPECT_EQ(vec.size(), 3);
+  EXPECT_TRUE(vec.contains(5));
+  EXPECT_TRUE(vec.contains(2));
+  EXPECT_TRUE(vec.contains(8));
+}



More information about the Bf-blender-cvs mailing list