std::ranges::all_of,std::ranges::any_of,std::ranges::none_of (3) - Linux Manuals
std::ranges::all_of,std::ranges::any_of,std::ranges::none_of: std::ranges::all_of,std::ranges::any_of,std::ranges::none_of
NAME
std::ranges::all_of,std::ranges::any_of,std::ranges::none_of - std::ranges::all_of,std::ranges::any_of,std::ranges::none_of
Synopsis
Defined in header <algorithm>
Call signature
template< InputIterator I, Sentinel<I> S, class Proj = std::identity,
IndirectUnaryPredicate<projected<I, Proj>> Pred > (1) (since C++20)
bool all_of( I first, S last, Pred pred, Proj proj = {} );
template< InputRange R, class Proj = std::identity,
IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred > (2) (since C++20)
bool all_of( R&& r, Pred pred, Proj proj = {} );
template< InputIterator I, Sentinel<I> S, class Proj = std::identity,
IndirectUnaryPredicate<projected<I, Proj>> Pred > (3) (since C++20)
bool any_of( I first, S last, Pred pred, Proj proj = {} );
template< InputRange R, class Proj = std::identity,
IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred > (4) (since C++20)
bool any_of( R&& r, Pred pred, Proj proj = {} );
template< InputIterator I, Sentinel<I> S, class Proj = std::identity,
IndirectUnaryPredicate<projected<I, Proj>> Pred > (5) (since C++20)
bool none_of( I first, S last, Pred pred, Proj proj = {} );
template< InputRange R, class Proj = std::identity,
IndirectUnaryPredicate<projected<ranges::iterator_t<R>, Proj>> Pred > (6) (since C++20)
bool none_of( R&& r, Pred pred, Proj proj = {} );
1) Checks if unary predicate pred returns true for all elements in the range [first, last) (after projecting with the projection proj).
3) Checks if unary predicate pred returns true for at least one element in the range [first, last) (after projecting with the projection proj).
5) Checks if unary predicate pred returns true for no elements in the range [first, last) (after projecting with the projection proj).
2,4,6) Same as (1,3,5), but uses r as the source range, as if using ranges::begin(r) as first and ranges::end(r) as last.
The function-like entities described on this page are niebloids, that is:
* Explicit template argument lists may not be specified when calling any of them.
* None of them is visible to argument-dependent_lookup.
* When one of them is found by normal_unqualified_lookup for the name to the left of the function-call operator, it inhibits argument-dependent_lookup.
In practice, they may be implemented as function objects, or with special compiler extensions.
Parameters
first, last - the range of the elements to examine
r - the range of the elements to examine
pred - predicate to apply to the projected elements
proj - projection to apply to the elements
Return value
1-2) true if std::invoke(pred, std::invoke(proj, *i)) != false for every iterator i in the range, false otherwise. Returns true if the range is empty.
3-4) true if std::invoke(pred, std::invoke(proj, *i)) != false for at least one iterator i in the range, false otherwise. Returns false if the range is empty.
5-6) true if std::invoke(pred, std::invoke(proj, *i)) == false for every iterator i in the range, false otherwise. Returns true if the range is empty.
Complexity
At most last - first applications of the predicate and the projection.
Possible implementation
First version
Second version
Third version
Example
// Run this code