| 1 |
.. title:: clang-tidy - readability-use-anyofallof |
| 2 |
|
| 3 |
readability-use-anyofallof |
| 4 |
========================== |
| 5 |
|
| 6 |
Finds range-based for loops that can be replaced by a call to ``std::any_of`` or |
| 7 |
``std::all_of``. In C++ 20 mode, suggests ``std::ranges::any_of`` or |
| 8 |
``std::ranges::all_of``. |
| 9 |
|
| 10 |
Example: |
| 11 |
|
| 12 |
.. code-block:: c++ |
| 13 |
|
| 14 |
bool all_even(std::vector<int> V) { |
| 15 |
for (int I : V) { |
| 16 |
if (I % 2) |
| 17 |
return false; |
| 18 |
} |
| 19 |
return true; |
| 20 |
// Replace loop by |
| 21 |
// return std::ranges::all_of(V, [](int I) { return I % 2 == 0; }); |
| 22 |
} |