[Bf-blender-cvs] [9c2715ffda9] master: BLI: add Map.is_empty() method
Jacques Lucke
noreply at git.blender.org
Tue Apr 28 11:44:24 CEST 2020
Commit: 9c2715ffda93a7625955a453a6dacaa4b601dd89
Author: Jacques Lucke
Date: Tue Apr 28 11:44:10 2020 +0200
Branches: master
https://developer.blender.org/rB9c2715ffda93a7625955a453a6dacaa4b601dd89
BLI: add Map.is_empty() method
===================================================================
M source/blender/blenlib/BLI_map.hh
M tests/gtests/blenlib/BLI_map_test.cc
===================================================================
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
@@ -415,6 +415,14 @@ class Map {
return m_array.slots_set();
}
+ /**
+ * 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.
*/
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)
More information about the Bf-blender-cvs
mailing list