Skip to content

Commit 4992afe

Browse files
committed
Minor c++20 changes
1 parent a3e5932 commit 4992afe

6 files changed

+10
-14
lines changed

src/backend/apidb/quad_tile.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ std::vector<tile_id_t> tiles_for_area(double minlat, double minlon, double maxla
3333
}
3434
}
3535

36-
std::sort(tiles.begin(), tiles.end());
36+
std::ranges::sort(tiles);
3737
tiles.erase(std::unique(tiles.begin(), tiles.end()), tiles.end());
3838

3939
return tiles;

src/backend/apidb/readonly_pgsql_selection.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ void readonly_pgsql_selection::fetch_changesets(const std::set< osm_changeset_id
874874

875875
// check if changeset is already contained in map
876876
for (auto id: all_ids) {
877-
if (cc.find(id) == cc.end()) {
877+
if (!cc.contains(id)) {
878878
ids.insert(id);
879879
}
880880
}
@@ -893,7 +893,7 @@ void readonly_pgsql_selection::fetch_changesets(const std::set< osm_changeset_id
893893
auto cs = r[0].as<int64_t>();
894894

895895
// Multiple results for one changeset?
896-
if (cc.find(cs) != cc.end()) {
896+
if (cc.contains(cs)) {
897897
logger::message(
898898
fmt::format("ERROR: Request for user data associated with changeset {:d} failed: returned multiple rows.", cs));
899899
throw http::server_error(
@@ -918,7 +918,7 @@ void readonly_pgsql_selection::fetch_changesets(const std::set< osm_changeset_id
918918

919919
// Missing changeset in query result?
920920
for (const auto & id : ids) {
921-
if (cc.find(id) == cc.end()) {
921+
if (!cc.contains(id)) {
922922
logger::message(
923923
fmt::format("ERROR: Request for user data associated with changeset {:d} failed: returned 0 rows.", id));
924924
throw http::server_error(

src/backend/apidb/transaction_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Transaction_Manager::Transaction_Manager(Transaction_Owner_Base &to) :
5353

5454
void Transaction_Manager::prepare(const std::string &name,
5555
const std::string &definition) {
56-
if (m_prep_stmt.find(name) == m_prep_stmt.end())
56+
if (!m_prep_stmt.contains(name))
5757
{
5858
m_txn.conn().prepare(name, definition);
5959
m_prep_stmt.insert(name);

src/bbox.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@
1515
bbox::bbox(double minlat_, double minlon_, double maxlat_, double maxlon_)
1616
: minlat(minlat_), minlon(minlon_), maxlat(maxlat_), maxlon(maxlon_) {}
1717

18-
bool bbox::operator==(const bbox &other) const {
19-
return ((minlat == other.minlat) &&
20-
(minlon == other.minlon) &&
21-
(maxlat == other.maxlat) &&
22-
(maxlon == other.maxlon));
23-
}
18+
bool bbox::operator==(const bbox &other) const = default;
2419

2520
bool bbox::parse(const std::string &s) {
2621
if (s.empty()) {

src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void get_options(int argc, char **argv, po::variables_map &options) {
160160
[&desc](const std::string &name) {
161161
std::string option;
162162
// convert an environment variable name to an option name
163-
if (name.substr(0, 7) == "CGIMAP_") {
163+
if (name.starts_with("CGIMAP_")) {
164164
std::transform(name.begin() + 7, name.end(),
165165
std::back_inserter(option),
166166
[](unsigned char c) {

src/oauth2.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
#include "cgimap/oauth2.hpp"
11+
#include <ranges>
1112
#include <sys/types.h>
1213

1314
#if HAVE_CRYPTOPP
@@ -52,7 +53,7 @@ namespace oauth2 {
5253
}
5354

5455
[[nodiscard]] bool has_forbidden_char(std::string_view str) {
55-
return !std::all_of(str.begin(), str.end(), is_valid_bearer_token_char);
56+
return !std::ranges::all_of(str, is_valid_bearer_token_char);
5657
}
5758

5859
[[nodiscard]] std::optional<osm_user_id_t> validate_bearer_token(const request &req, data_selection& selection, bool& allow_api_write)
@@ -64,7 +65,7 @@ namespace oauth2 {
6465
const auto auth_header = std::string(auth_hdr);
6566

6667
// Auth header starts with Bearer?
67-
if (auth_header.rfind("Bearer ", 0) == std::string::npos)
68+
if (!auth_header.starts_with("Bearer "))
6869
return std::nullopt;
6970

7071
const auto bearer_token = auth_header.substr(7);

0 commit comments

Comments
 (0)