Replace find method with contains method
- The intent behind of this commit is to replace the `find` method
with the `contains` method.
- `contains` is a new feature of C++20, it will check if there is an
element with key equivalent to key in the container and return
true or false.
Tested: built ledManager repo successfully and CI passed.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I09121154983defe051c48e6470a976c5b229a2e7
diff --git a/json-config.hpp b/json-config.hpp
index d3a59a1..b9bb36f 100644
--- a/json-config.hpp
+++ b/json-config.hpp
@@ -104,7 +104,7 @@
msg.read(path, interfaces);
- if (interfaces.find(confCompatibleInterface) == interfaces.end())
+ if (!interfaces.contains(confCompatibleInterface))
{
return;
}
@@ -113,7 +113,7 @@
// "xyz.openbmc_project.Configuration.IBMCompatibleSystem" interface
const auto& properties = interfaces.at(confCompatibleInterface);
- if (properties.find(confCompatibleProperty) == properties.end())
+ if (!properties.contains(confCompatibleProperty))
{
return;
}
diff --git a/manager.cpp b/manager.cpp
index 6f286df..fe0f605 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -26,8 +26,7 @@
}
else
{
- auto search = assertedGroups.find(&ledMap.at(path));
- if (search != assertedGroups.end())
+ if (assertedGroups.contains(&ledMap.at(path)))
{
assertedGroups.erase(&ledMap.at(path));
}
diff --git a/serialize.cpp b/serialize.cpp
index c8f4e66..897b336 100644
--- a/serialize.cpp
+++ b/serialize.cpp
@@ -22,7 +22,7 @@
bool Serialize::getGroupSavedState(const std::string& objPath) const
{
- return savedGroups.find(objPath) == savedGroups.end() ? false : true;
+ return savedGroups.contains(objPath);
}
void Serialize::storeGroups(const std::string& group, bool asserted)
diff --git a/test/utest-led-json.cpp b/test/utest-led-json.cpp
index a8c7398..e2d8edb 100644
--- a/test/utest-led-json.cpp
+++ b/test/utest-led-json.cpp
@@ -12,9 +12,9 @@
std::string powerOn = objPath + "/power_on";
std::string enclosureIdentify = objPath + "/enclosure_identify";
- ASSERT_NE(ledMap.find(bmcBooted), ledMap.end());
- ASSERT_NE(ledMap.find(powerOn), ledMap.end());
- ASSERT_NE(ledMap.find(enclosureIdentify), ledMap.end());
+ ASSERT_EQ(ledMap.contains(bmcBooted), true);
+ ASSERT_EQ(ledMap.contains(powerOn), true);
+ ASSERT_EQ(ledMap.contains(enclosureIdentify), true);
LedAction bmcBootedActions = ledMap.at(bmcBooted);
LedAction powerOnActions = ledMap.at(powerOn);