Skip to content

Commit bfda3a7

Browse files
authored
style(clang-tidy): fix modernize-use-ranges checks (#1802)
Signed-off-by: Balakrishna Avulapati <ba@bavulapati.com>
1 parent ef8f620 commit bfda3a7

File tree

8 files changed

+33
-38
lines changed

8 files changed

+33
-38
lines changed

src/core/json/json_value.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ auto JSON::push_back_if_unique(const JSON &value)
777777
-> std::pair<std::reference_wrapper<const JSON>, bool> {
778778
assert(this->is_array());
779779
auto &array_data{this->as_array().data};
780-
const auto match{std::find(array_data.cbegin(), array_data.cend(), value)};
780+
const auto match{std::ranges::find(array_data, value)};
781781
if (match == array_data.cend()) {
782782
array_data.push_back(value);
783783
return {array_data.back(), true};
@@ -790,7 +790,7 @@ auto JSON::push_back_if_unique(JSON &&value)
790790
-> std::pair<std::reference_wrapper<const JSON>, bool> {
791791
assert(this->is_array());
792792
auto &array_data{this->as_array().data};
793-
const auto match{std::find(array_data.cbegin(), array_data.cend(), value)};
793+
const auto match{std::ranges::find(array_data, value)};
794794
if (match == array_data.cend()) {
795795
array_data.push_back(std::move(value));
796796
return {array_data.back(), true};

src/core/json/stringify.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ auto stringify(
425425
std::transform(std::cbegin(document), std::cend(document),
426426
std::back_inserter(keys),
427427
[](const auto &property) { return property.first; });
428-
std::sort(std::begin(keys), std::end(keys), compare);
428+
std::ranges::sort(keys, compare);
429429
const auto end{std::cend(keys)};
430430
for (auto iterator = std::cbegin(keys); iterator != end; ++iterator) {
431431
stringify<Allocator>(*iterator, stream);
@@ -529,7 +529,7 @@ auto prettify(
529529
std::transform(std::cbegin(document), std::cend(document),
530530
std::back_inserter(keys),
531531
[](const auto &property) { return property.first; });
532-
std::sort(std::begin(keys), std::end(keys), compare);
532+
std::ranges::sort(keys, compare);
533533
const auto end{std::cend(keys)};
534534
for (auto iterator = std::cbegin(keys); iterator != end; ++iterator) {
535535
stream.put(internal::token_whitespace_line_feed<typename JSON::Char>);

src/core/jsonschema/frame.cc

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ auto traverse_origin_instance_locations(
250250
sourcemeta::core::SchemaFrame::Instances::mapped_type &destination)
251251
-> void {
252252
if (accumulator.has_value() &&
253-
std::find(destination.cbegin(), destination.cend(),
254-
accumulator.value()) == destination.cend()) {
253+
std::ranges::find(destination, accumulator.value()) ==
254+
destination.cend()) {
255255
destination.push_back(accumulator.value());
256256
}
257257

@@ -319,8 +319,7 @@ auto repopulate_instance_locations(
319319
result.emplace_back(token);
320320
}
321321

322-
if (std::find(destination.cbegin(), destination.cend(), result) ==
323-
destination.cend()) {
322+
if (std::ranges::find(destination, result) == destination.cend()) {
324323
destination.push_back(result);
325324
}
326325

@@ -423,10 +422,9 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
423422
for (const auto &path : paths) {
424423
// Passing paths that overlap is undefined behavior. No path should
425424
// start with another one, else you are doing something wrong
426-
assert(
427-
std::all_of(paths.cbegin(), paths.cend(), [&path](const auto &other) {
428-
return path == other || !path.starts_with(other);
429-
}));
425+
assert(std::ranges::all_of(paths, [&path](const auto &other) {
426+
return path == other || !path.starts_with(other);
427+
}));
430428

431429
const auto &schema{get(root, path)};
432430

@@ -730,7 +728,7 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
730728
const auto pointer_walker{sourcemeta::core::PointerWalker{schema}};
731729
std::vector<sourcemeta::core::Pointer> pointers{pointer_walker.cbegin(),
732730
pointer_walker.cend()};
733-
std::sort(pointers.begin(), pointers.end(), std::less<>());
731+
std::ranges::sort(pointers, std::less<>());
734732

735733
// Pre-compute every possible pointer to the schema
736734
for (const auto &relative_pointer : pointers) {
@@ -995,19 +993,17 @@ auto SchemaFrame::references() const noexcept -> const References & {
995993
}
996994

997995
auto SchemaFrame::standalone() const -> bool {
998-
return std::all_of(
999-
this->references_.cbegin(), this->references_.cend(),
1000-
[&](const auto &reference) {
1001-
assert(!reference.first.second.empty());
1002-
assert(reference.first.second.back().is_property());
1003-
// TODO: This check might need to be more elaborate given
1004-
// https://github.com/sourcemeta/core/issues/1390
1005-
return reference.first.second.back().to_property() == "$schema" ||
1006-
this->locations_.contains({SchemaReferenceType::Static,
1007-
reference.second.destination}) ||
1008-
this->locations_.contains({SchemaReferenceType::Dynamic,
1009-
reference.second.destination});
1010-
});
996+
return std::ranges::all_of(this->references_, [&](const auto &reference) {
997+
assert(!reference.first.second.empty());
998+
assert(reference.first.second.back().is_property());
999+
// TODO: This check might need to be more elaborate given
1000+
// https://github.com/sourcemeta/core/issues/1390
1001+
return reference.first.second.back().to_property() == "$schema" ||
1002+
this->locations_.contains(
1003+
{SchemaReferenceType::Static, reference.second.destination}) ||
1004+
this->locations_.contains(
1005+
{SchemaReferenceType::Dynamic, reference.second.destination});
1006+
});
10111007
}
10121008

10131009
auto SchemaFrame::vocabularies(const Location &location,

src/core/jsonschema/walker.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,8 @@ sourcemeta::core::SchemaKeywordIterator::SchemaKeywordIterator(
481481
}
482482

483483
// Sort keywords based on priority for correct evaluation
484-
std::sort(
485-
this->entries.begin(), this->entries.end(),
484+
std::ranges::sort(
485+
this->entries,
486486
[&vocabularies, &walker](const auto &left, const auto &right) -> bool {
487487
// These cannot be empty or indexes, as we created
488488
// the entries array from a JSON object

src/core/uri/escaping.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ auto uri_unescape(std::istream &input, std::ostream &output) -> void {
8989
const std::string input_string{input_stream.str()};
9090
auto const buffer = new std::string::value_type[input_string.size() + 1];
9191
try {
92-
std::copy(input_string.cbegin(), input_string.cend(), buffer);
92+
std::ranges::copy(input_string, buffer);
9393
} catch (...) {
9494
delete[] buffer;
9595
throw;

src/core/uri/uri.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ auto URI::from_path(const std::filesystem::path &path) -> URI {
734734
const auto is_unc{normalized.starts_with("\\\\")};
735735
const auto is_windows_absolute{normalized.size() >= 2 &&
736736
normalized[1] == ':'};
737-
std::replace(normalized.begin(), normalized.end(), '\\', '/');
737+
std::ranges::replace(normalized, '\\', '/');
738738
const auto is_unix_absolute{normalized.starts_with("/")};
739739
if (!is_unix_absolute && !is_windows_absolute && !is_unc) {
740740
throw URIError(

src/extension/alterschema/alterschema.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ namespace sourcemeta::core {
1111
static auto
1212
contains_any(const Vocabularies &container,
1313
const std::set<typename Vocabularies::key_type> &values) -> bool {
14-
return std::any_of(std::cbegin(container), std::cend(container),
15-
[&values](const auto &element) {
16-
return values.contains(element.first);
17-
});
14+
return std::ranges::any_of(container, [&values](const auto &element) {
15+
return values.contains(element.first);
16+
});
1817
}
1918

2019
template <typename T>

src/extension/alterschema/linter/non_applicable_type_specific_keywords.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ class NonApplicableTypeSpecificKeywords final : public SchemaTransformRule {
5959

6060
// If none of the types that the keyword applies to is a valid
6161
// type for the current schema, then by definition we can remove it
62-
if (std::none_of(metadata.instances.cbegin(), metadata.instances.cend(),
63-
[&current_types](const auto keyword_type) {
64-
return current_types.contains(keyword_type);
65-
})) {
62+
if (std::ranges::none_of(metadata.instances,
63+
[&current_types](const auto keyword_type) {
64+
return current_types.contains(keyword_type);
65+
})) {
6666
this->blacklist.emplace_back(entry.first);
6767
}
6868
}

0 commit comments

Comments
 (0)