diff options
author | Ed Tanous <edtanous@google.com> | 2023-08-07 04:12:20 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2023-08-21 22:29:33 +0300 |
commit | 3544d2a719c8bb7b07f9a39f61a3770ec84b909f (patch) | |
tree | dcce5cb8ee0219d04eea93d3f639f62e1f1c05a1 /redfish-core/include/utils | |
parent | 5ab47856f8499a5d2d393d1584b8fc402399eddf (diff) | |
download | bmcweb-3544d2a719c8bb7b07f9a39f61a3770ec84b909f.tar.xz |
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>
Diffstat (limited to 'redfish-core/include/utils')
-rw-r--r-- | redfish-core/include/utils/collection.hpp | 4 | ||||
-rw-r--r-- | redfish-core/include/utils/json_utils.hpp | 3 | ||||
-rw-r--r-- | redfish-core/include/utils/query_param.hpp | 6 | ||||
-rw-r--r-- | redfish-core/include/utils/sw_utils.hpp | 8 |
4 files changed, 11 insertions, 10 deletions
diff --git a/redfish-core/include/utils/collection.hpp b/redfish-core/include/utils/collection.hpp index 862be90efd..0801cd5f4a 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 @@ inline void } 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 5b4ad9a545..f4e5385566 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 @@ struct ODataObjectLess // 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 696e323d96..5fa4852390 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 @@ inline void recursiveSelect(nlohmann::json& currRoot, 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 cffc637ff7..4e1e066b3c 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 @@ inline void populateSoftwareInformation( // 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 @@ inline void } 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; |