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/include/http_utility.hpp b/include/http_utility.hpp
index eb54d0b..2fd5e14 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 @@
{
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 @@
}
// 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 521ff65..2e3e689 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 @@
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 5ac196d..f707abf 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 @@
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 6211fcc..7c47bcc 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 @@
}
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)