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 /include | |
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 'include')
-rw-r--r-- | include/http_utility.hpp | 13 | ||||
-rw-r--r-- | include/image_upload.hpp | 6 | ||||
-rw-r--r-- | include/multipart_parser.hpp | 3 | ||||
-rw-r--r-- | include/openbmc_dbus_rest.hpp | 3 |
4 files changed, 14 insertions, 11 deletions
diff --git a/include/http_utility.hpp b/include/http_utility.hpp index eb54d0b194..2fd5e14016 100644 --- a/include/http_utility.hpp +++ b/include/http_utility.hpp @@ -8,6 +8,7 @@ #include <cctype> #include <iomanip> #include <ostream> +#include <ranges> #include <span> #include <string> #include <string_view> @@ -75,10 +76,9 @@ inline ContentType { return ContentType::ANY; } - const auto* knownContentType = - std::find_if(contentTypes.begin(), contentTypes.end(), - [encoding](const ContentTypePair& pair) { - return pair.contentTypeString == encoding; + const auto* knownContentType = std::ranges::find_if( + contentTypes, [encoding](const ContentTypePair& pair) { + return pair.contentTypeString == encoding; }); if (knownContentType == contentTypes.end()) @@ -88,8 +88,9 @@ inline ContentType } // Not one of the types requested - if (std::find(preferedOrder.begin(), preferedOrder.end(), - knownContentType->contentTypeEnum) == preferedOrder.end()) + if (std::ranges::find(preferedOrder, + knownContentType->contentTypeEnum) == + preferedOrder.end()) { continue; } diff --git a/include/image_upload.hpp b/include/image_upload.hpp index 521ff659f6..2e3e689c0e 100644 --- a/include/image_upload.hpp +++ b/include/image_upload.hpp @@ -10,6 +10,7 @@ #include <cstdio> #include <fstream> #include <memory> +#include <ranges> namespace crow { @@ -66,9 +67,8 @@ inline void dbus::utility::DBusInteracesMap interfaces; m.read(path, interfaces); - if (std::find_if(interfaces.begin(), interfaces.end(), - [](const auto& i) { - return i.first == "xyz.openbmc_project.Software.Version"; + if (std::ranges::find_if(interfaces, [](const auto& i) { + return i.first == "xyz.openbmc_project.Software.Version"; }) != interfaces.end()) { timeout.cancel(); diff --git a/include/multipart_parser.hpp b/include/multipart_parser.hpp index 5ac196dd31..f707abfa5a 100644 --- a/include/multipart_parser.hpp +++ b/include/multipart_parser.hpp @@ -4,6 +4,7 @@ #include <boost/beast/http/fields.hpp> +#include <ranges> #include <string> #include <string_view> @@ -224,7 +225,7 @@ class MultipartParser private: void indexBoundary() { - std::fill(boundaryIndex.begin(), boundaryIndex.end(), 0); + std::ranges::fill(boundaryIndex, 0); for (const char current : boundary) { boundaryIndex[static_cast<unsigned char>(current)] = true; diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index 6211fccfa2..7c47bcc5fc 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -56,6 +56,7 @@ #include <limits> #include <map> #include <memory> +#include <ranges> #include <regex> #include <string> #include <string_view> @@ -2443,7 +2444,7 @@ inline void requestRoutes(App& app) } else { - std::sort(names.begin(), names.end()); + std::ranges::sort(names); asyncResp->res.jsonValue["status"] = "ok"; auto& objectsSub = asyncResp->res.jsonValue["objects"]; for (const auto& name : names) |