[Bf-blender-cvs] [c05ef1459c6] master: BLI: add Set.clear method
Jacques Lucke
noreply at git.blender.org
Tue Apr 28 16:41:45 CEST 2020
Commit: c05ef1459c68e0a37e645b1c32caeea0961edef5
Author: Jacques Lucke
Date: Tue Apr 28 16:41:37 2020 +0200
Branches: master
https://developer.blender.org/rBc05ef1459c68e0a37e645b1c32caeea0961edef5
BLI: add Set.clear method
===================================================================
M source/blender/blenlib/BLI_set.hh
M tests/gtests/blenlib/BLI_set_test.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_set.hh b/source/blender/blenlib/BLI_set.hh
index f9d4bbfaed4..dc9df5d116a 100644
--- a/source/blender/blenlib/BLI_set.hh
+++ b/source/blender/blenlib/BLI_set.hh
@@ -284,6 +284,12 @@ class Set {
return this->size() == 0;
}
+ void clear()
+ {
+ this->~Set();
+ new (this) Set();
+ }
+
/**
* Returns true when there is at least one element that is in both sets.
* Otherwise false.
diff --git a/tests/gtests/blenlib/BLI_set_test.cc b/tests/gtests/blenlib/BLI_set_test.cc
index ae46c2bf52e..90c052d7d2b 100644
--- a/tests/gtests/blenlib/BLI_set_test.cc
+++ b/tests/gtests/blenlib/BLI_set_test.cc
@@ -194,3 +194,11 @@ TEST(set, UniquePtrValues)
EXPECT_EQ(set.size(), 3);
}
+
+TEST(set, Clear)
+{
+ Set<int> set = {3, 4, 6, 7};
+ EXPECT_EQ(set.size(), 4);
+ set.clear();
+ EXPECT_EQ(set.size(), 0);
+}
More information about the Bf-blender-cvs
mailing list