?
std::any_of
template
bool any_of (InputIterator first, InputIterator last, UnaryPredicate pred);
Test if any element in range fulfills condition Returns
true if
pred returns
true for any of the elements in the range
[first,last), and
false otherwise.
如果范围内任一元素使pred返回true,则返回true,否则返回false.
例子:
?
#include
#include
using namespace std; bool isGreat(int i){ if(i>=5){ cout<
=5<< ,match!<
vi{0,1,2,3,4,5,6}; if(any_of(vi.begin(),vi.end(),isGreat)) cout<
=5 <
=1 <
运行截图:
?

If [first,last) is an empty range, the function returns false.
如果范围为空,则返回false.(因为没有任一匹配)
例子:
?
#include
#include
using namespace std; bool isGreat(int i){ if(i>=5){ cout<
=5<< ,match!<
vi{0,1,2,3,4,5,6}; if(any_of(vi.begin(),vi.begin(),isGreat)) cout<
?
The behavior of this function template is equivalent to:
?
|