Use ranges
C++20 brought us std::ranges for a lot of algorithms. Most of these
conversions were done using comby, similar to:
```
comby -verbose 'std::lower_bound(:[a].begin(),:[b].end(),:[c])' 'std::ranges::lower_bound(:[a], :[c])' $(git ls-files | grep "\.[hc]\(pp\)\?$") -in-place
```
Change-Id: I0c99c04e9368312555c08147d474ca93a5959e8d
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/redfish-core/include/utils/collection.hpp b/redfish-core/include/utils/collection.hpp
index 862be90..0801cd5 100644
--- a/redfish-core/include/utils/collection.hpp
+++ b/redfish-core/include/utils/collection.hpp
@@ -9,6 +9,7 @@
#include <boost/url/url.hpp>
#include <nlohmann/json.hpp>
+#include <ranges>
#include <span>
#include <string>
#include <string_view>
@@ -68,8 +69,7 @@
}
pathNames.push_back(leaf);
}
- std::sort(pathNames.begin(), pathNames.end(),
- AlphanumLess<std::string>());
+ std::ranges::sort(pathNames, AlphanumLess<std::string>());
nlohmann::json& members = asyncResp->res.jsonValue["Members"];
members = nlohmann::json::array();
diff --git a/redfish-core/include/utils/json_utils.hpp b/redfish-core/include/utils/json_utils.hpp
index 5b4ad9a..f4e5385 100644
--- a/redfish-core/include/utils/json_utils.hpp
+++ b/redfish-core/include/utils/json_utils.hpp
@@ -32,6 +32,7 @@
#include <limits>
#include <map>
#include <optional>
+#include <ranges>
#include <span>
#include <string>
#include <string_view>
@@ -670,7 +671,7 @@
// those whose |element[key]| is string.
inline void sortJsonArrayByOData(nlohmann::json::array_t& array)
{
- std::sort(array.begin(), array.end(), ODataObjectLess());
+ std::ranges::sort(array, ODataObjectLess());
}
// Returns the estimated size of the JSON value
diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp
index 696e323..5fa4852 100644
--- a/redfish-core/include/utils/query_param.hpp
+++ b/redfish-core/include/utils/query_param.hpp
@@ -30,6 +30,7 @@
#include <map>
#include <memory>
#include <optional>
+#include <ranges>
#include <string>
#include <string_view>
#include <system_error>
@@ -960,9 +961,8 @@
constexpr std::array<std::string_view, 5> reservedProperties = {
"@odata.id", "@odata.type", "@odata.context", "@odata.etag",
"error"};
- bool reserved = std::find(reservedProperties.begin(),
- reservedProperties.end(),
- it.key()) != reservedProperties.end();
+ bool reserved = std::ranges::find(reservedProperties, it.key()) !=
+ reservedProperties.end();
if (reserved || (nextNode != nullptr && nextNode->isSelected()))
{
it = nextIt;
diff --git a/redfish-core/include/utils/sw_utils.hpp b/redfish-core/include/utils/sw_utils.hpp
index cffc637..4e1e066 100644
--- a/redfish-core/include/utils/sw_utils.hpp
+++ b/redfish-core/include/utils/sw_utils.hpp
@@ -13,6 +13,7 @@
#include <algorithm>
#include <array>
+#include <ranges>
#include <string>
#include <string_view>
#include <vector>
@@ -125,8 +126,8 @@
// Look at Ids from
// /xyz/openbmc_project/software/functional
// to determine if this is a running image
- if (std::find(functionalSwIds.begin(), functionalSwIds.end(),
- swId) != functionalSwIds.end())
+ if (std::ranges::find(functionalSwIds, swId) !=
+ functionalSwIds.end())
{
runningImage = true;
}
@@ -367,8 +368,7 @@
}
std::string reqSwObjPath = "/xyz/openbmc_project/software/" + *swId;
- if (std::find(objPaths.begin(), objPaths.end(), reqSwObjPath) !=
- objPaths.end())
+ if (std::ranges::find(objPaths, reqSwObjPath) != objPaths.end())
{
asyncResp->res.jsonValue["Updateable"] = true;
return;