Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-10-19 06:15:52 +0300
committerHans Goudey <h.goudey@me.com>2021-10-19 06:15:52 +0300
commita76bb1a27782317449c04c0ab4916d66c46b6803 (patch)
tree63cea49df980078f7d05efaef2a5473738b6a1ee /source/blender/blenlib/tests/BLI_set_test.cc
parentda949c357405ad01b00e83177335f55d113a8619 (diff)
BLI: Support removing keys from a set during iteration
This adds the ability to mark slots as removed while iterating through a mutable set. Differential Revision: https://developer.blender.org/D12867
Diffstat (limited to 'source/blender/blenlib/tests/BLI_set_test.cc')
-rw-r--r--source/blender/blenlib/tests/BLI_set_test.cc26
1 files changed, 26 insertions, 0 deletions
diff --git a/source/blender/blenlib/tests/BLI_set_test.cc b/source/blender/blenlib/tests/BLI_set_test.cc
index 3a4733a218f..28eb4df2ca6 100644
--- a/source/blender/blenlib/tests/BLI_set_test.cc
+++ b/source/blender/blenlib/tests/BLI_set_test.cc
@@ -544,6 +544,32 @@ TEST(set, GenericAlgorithms)
EXPECT_EQ(std::count(set.begin(), set.end(), 20), 1);
}
+TEST(set, RemoveDuringIteration)
+{
+ Set<int> set;
+ set.add(6);
+ set.add(5);
+ set.add(2);
+ set.add(3);
+
+ EXPECT_EQ(set.size(), 4);
+
+ using Iter = Set<int>::Iterator;
+ Iter begin = set.begin();
+ Iter end = set.end();
+ for (Iter iter = begin; iter != end; ++iter) {
+ int item = *iter;
+ if (item == 2) {
+ set.remove(iter);
+ }
+ }
+
+ EXPECT_EQ(set.size(), 3);
+ EXPECT_TRUE(set.contains(5));
+ EXPECT_TRUE(set.contains(6));
+ EXPECT_TRUE(set.contains(3));
+}
+
/**
* Set this to 1 to activate the benchmark. It is disabled by default, because it prints a lot.
*/