homebrew version of ROOT keeps c++17 base on the default compiler, which may be old now.
#include <algorithm>
#include <ranges>
#include <vector>
#include <iostream>
#include "Rtypes.h" // for Bool_t / kTRUE etc. (optional)
void test_ranges_anyof() {
std::vector v{1, 2, 3, 4, 5};
auto is_even = [ ](int x) { return x % 2 == 0; };
// --- the actual test -------------------------------------------------
Bool_t has_even = std::ranges::any_of(v, is_even);
Bool_t has_neg = std::ranges::any_of(v, [ ](int x) { return x < 0; });
std::cout << "vector = {1,2,3,4,5}\\n";
std::cout << "any_of even? = " << std::boolalpha << (bool)has_even << '\\n';
std::cout << "any_of neg? = " << std::boolalpha << (bool)has_neg << '\\n';
// ranges over a built-in array via std::ranges::subrange / views -----
int a[ ]{10, 21, 33};
Bool_t any_mult_of_10 = std::ranges::any_of(a, [ ](int x){ return x % 10 == 0; });
std::cout << "array {10,21,33} any mult of 10? = "
<< std::boolalpha << (bool)any_mult_of_10 << '\\n';
// sanity check --------------------------------------------------------
bool ok = has_even && !has_neg && any_mult_of_10;
std::cout << "\\nRESULT: std::ranges::any_of "
<< (ok ? "WORKS ✓" : "FAILED ✗") << '\\n';
}
Processing test_ranges_anyof.C…
In file included from input_line_1:1:
/home/linuxbrew/.linuxbrew/Cellar/root/6.40.02_1/etc/root/cling/std.modulemap:281:10: error: module ‘std.ranges’ requires feature ‘cplusplus20’
module “ranges” {
^
/home/cx/test_ranges_anyof.C:8:10: note: submodule of top-level module ‘std’ implicitly imported here
#include
^
/home/cx/test_ranges_anyof.C:20:27: error: no member named ‘ranges’ in namespace ‘std’
Bool_t has_even = std::ranges::any_of(v, is_even);
~~~~~^
/home/cx/test_ranges_anyof.C:21:27: error: no member named ‘ranges’ in namespace ‘std’
Bool_t has_neg = std::ranges::any_of(v, (int x) { return x < 0; });
~~~~~^
/home/cx/test_ranges_anyof.C:29:33: error: no member named ‘ranges’ in namespace ‘std’
Bool_t any_mult_of_10 = std::ranges::any_of(a, (int x){ return x % 10 == 0; });
```