是否有一种STL/boost算法可以测试两个迭代器之间的所有元素是否都与给定值匹配?或者,谓词返回所有这些参数的true
?
也就是说,类似于
template<class InputIterator, class T>
InputIterator all_match (InputIterator first, InputIterator last, const T& value)
{
bool allMatch = true;
while(allMatch && first!=last)
allMatch = (value == *first++);
return allMatch;
}
或
template <class InputIterator, class Predicate>
bool all_true (InputIterator first, InputIterator last, Predicate pred)
{
bool allTrue = true;
while (allTrue && first != last)
allTrue = pred(*first++);
return allTrue;
}
https://stackoverflow.com/questions/4225029
复制相似问题