diff options
author | Jacques Lucke <jacques@blender.org> | 2020-04-28 12:44:10 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-04-28 12:44:10 +0300 |
commit | 9c2715ffda93a7625955a453a6dacaa4b601dd89 (patch) | |
tree | d85f626b8a750df7de9a3bfdf48a788de1b5b9da | |
parent | 7acc8a5a929b899bf0c0dd63bda4dd6b9c6c8aed (diff) |
BLI: add Map.is_empty() method
-rw-r--r-- | source/blender/blenlib/BLI_map.hh | 8 | ||||
-rw-r--r-- | tests/gtests/blenlib/BLI_map_test.cc | 4 |
2 files changed, 12 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_map.hh b/source/blender/blenlib/BLI_map.hh index 553175b0395..eb9c6372995 100644 --- a/source/blender/blenlib/BLI_map.hh +++ b/source/blender/blenlib/BLI_map.hh @@ -416,6 +416,14 @@ class Map { } /** + * Returns true if there are no elements in the map. + */ + bool is_empty() const + { + return this->size() == 0; + } + + /** * Calls the given function for each key-value-pair. */ template<typename FuncT> void foreach_item(const FuncT &func) const diff --git a/tests/gtests/blenlib/BLI_map_test.cc b/tests/gtests/blenlib/BLI_map_test.cc index 2d052635c88..e9e4b1895ab 100644 --- a/tests/gtests/blenlib/BLI_map_test.cc +++ b/tests/gtests/blenlib/BLI_map_test.cc @@ -9,16 +9,20 @@ TEST(map, DefaultConstructor) { IntFloatMap map; EXPECT_EQ(map.size(), 0); + EXPECT_TRUE(map.is_empty()); } TEST(map, AddIncreasesSize) { IntFloatMap map; EXPECT_EQ(map.size(), 0); + EXPECT_TRUE(map.is_empty()); map.add(2, 5.0f); EXPECT_EQ(map.size(), 1); + EXPECT_FALSE(map.is_empty()); map.add(6, 2.0f); EXPECT_EQ(map.size(), 2); + EXPECT_FALSE(map.is_empty()); } TEST(map, Contains) |