函数调用形式:
template <class InputIterator, class UnaryPredicate> bool all_of (InputIterator first, InputIterator last, UnaryPredicate pred);Test condition on all elements in range
针对范围内所有元素的检测条件
Returns true
if pred returns true
for all the elements in the range [first,last)
or if the range is empty, and false
otherwise
如果所有元素的检测结果都为true,则函数返回true,否则,返回false。
The behavior of this function template is equivalent to:
函数的具体行为与如下类似:
template<class InputIterator, class UnaryPredicate>
bool all_of (InputIterator first, InputIterator last, UnaryPredicate pred)
{
while (first!=last) {
if (!pred(*first)) return false;
++first;
}
return true;
}
Parameters
-
first, last
-
Input iterators to the initial and final positions in a sequence. The range used is
[first,last)
, which contains all the elements between first and last, including the element pointed by first but not the element pointed by last. - 输入的迭代器分别是序列的首位置和末位置。范围为[first,last),包括first指向的元素,但是不包括last指向的元素。 pred
-
Unary function that accepts an element in the range as argument and returns a value convertible to
bool
. The value returned indicates whether the element fulfills the condition checked by this function.
The function shall not modify its argument.
This can either be a function pointer or a function object. - 一元函数接收单个元素作为参数并检测该值是否符合条件。
- 这个函数不会因为单个元素发生变化(判断规则一致)。
- 这里也可以是一个指向函数对象的指针。
-