templateTest if any element in range fulfills condition Returnsbool any_of (InputIterator first, InputIterator last, UnaryPredicate pred);
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 returnsfalse
.如果范圍為空,則返回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: