CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
65 lines
1.8 KiB
ReStructuredText
65 lines
1.8 KiB
ReStructuredText
.. title:: clang-tidy - readability-use-anyofallof
|
|
|
|
readability-use-anyofallof
|
|
==========================
|
|
|
|
Finds range-based for loops that can be replaced by a call to
|
|
``std::any_of`` or ``std::all_of``. In C++20 mode, suggests
|
|
``std::ranges::any_of`` or ``std::ranges::all_of``.
|
|
|
|
Example:
|
|
|
|
.. code-block:: c++
|
|
|
|
bool all_even(const std::vector<int> &V) {
|
|
for (int I : V) {
|
|
if (I % 2)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
// Replace loop by
|
|
// return std::ranges::all_of(V, [](int I) { return I % 2 == 0; }); (C++20)
|
|
// return std::all_of(V.begin(), V.end(), [](int I) { return I % 2 == 0; }); (pre-C++20)
|
|
|
|
When using a raw initializer list or a temporary range (pre-C++20), it's
|
|
recommended to materialize it in a local variable first to avoid potential
|
|
lifetime issues. In C++20, temporary ranges can be used directly with
|
|
``std::ranges`` algorithms as they handle the lifetime of a temporary range
|
|
correctly.
|
|
|
|
Example with raw initializer list:
|
|
|
|
.. code-block:: c++
|
|
|
|
bool contains_zero(int a, int b, int c) {
|
|
for (int i : {a, b, c}) {
|
|
if (i == 0)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
// Replace loop by
|
|
// auto range = {a, b, c};
|
|
// return std::ranges::any_of(range, [](int i) { return i == 0; }); (C++20)
|
|
// return std::any_of(range.begin(), range.end(), [](int i) { return i == 0; }); (pre-C++20)
|
|
|
|
Example with temporary range:
|
|
|
|
.. code-block:: c++
|
|
|
|
extern std::vector<int> get_values();
|
|
|
|
bool has_even() {
|
|
for (int i : get_values()) {
|
|
if (i % 2 == 0)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
// Replace loop by
|
|
// return std::ranges::any_of(get_values(), [](int i) { return i % 2 == 0; }); (C++20)
|
|
//
|
|
// auto values = get_values();
|
|
// return std::any_of(values.begin(), values.end(), [](int i) { return i % 2 == 0; }); (pre-C++20)
|