C++ Logo


Advanced search

Subject: [std-proposals] std::any_of, std::all_of and std::none_of without predicate
From: Bernhard Manfred Gruber (bernhardmgruber_at_[hidden])
Date: 2019-12-15 09:33:55

I sometimes intuitively write something along the lines:
if (std::any_of(begin(v), end(v))) { }

where v is a container of bools or something similar. And when I compile my
code, reality hits. The std::any_of, std::all_of and std::none_of
algorithms can only be called with a predicate as third argument.

So I need to write
if (std::any_of(begin(v), end(v), [](auto e) { return e; })) { }

Or in C++20 I might be able to use std::identity. Still, the third argument
feels unnecessary to me.

This has been discussed before here:
But the discussion quickly went off into various different proposals.

Is there a compelling reason, why std::any_of, std::all_of and std::none_of
do not have an overload without a predicate and just convert the elements
of the passed range to bool?
It feels like an oversight to me. Or maybe the use case is just too small?

Anyway, thank you for the feedback!

STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups