C++ Logo


Advanced search

std::any_of, std::all_of and std::none_of without predicate

From: Bernhard Manfred Gruber <bernhardmgruber_at_[hidden]>
Date: Sun, 15 Dec 2019 16:33:55 +0100
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!

Received on 2019-12-15 09:36:30