llvm / llvm/llvm-project

[clang-tidy] Make `readability-use-anyofallof` check suggest usage of 'std::none_of'

Open
#167,375 3 comments 0 reactions 0 assignees View on GitHub
clang-tidy enhancement
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Currently, we only diagnose suggestions with `std::all_of`, `std::any_of`.
I think we can add some heuristics to print to suggest for `std::none_of` too.
E.g. given this code:

```cpp
for (auto E : S1)
if (S2.count(E) == 0)
return false;
return true;
```

It's arguably better to write `none_of` than `any_of`:
```cpp
// we did't change predicate at all
return std::ranges::none_of(S1, [&S2](const auto& E) { return S2.count(E) == 0; });
// we changed predicate to '!='
return std::ranges::all_of(S1, [&S2](const auto& E) { return S2.count(E) != 0; });
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.