Skip to content

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

@vbvictor

Description

@vbvictor

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:

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

It's arguably better to write none_of than any_of:

// 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; });

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang-tidyenhancementImproving things as opposed to bug fixing, e.g. new or missing feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions