2つのイテレータ間のすべての要素が特定の値と一致するかどうかをテストするSTL /ブーストアルゴリズムはありますか?あるいは、述語がすべてtrue
を返しますか?コンテナ内のすべての要素が値と一致することを確認するSTL /ブーストアルゴリズムはありますか?
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;
}
それはうまくいくでしょう。ありがとう。 – GrahamS
実際、私は 'not_equal_to()'の構文がかなり正しいとは思わない。私は何か間違っているかもしれませんが、 'std :: not_equal_to()のように' std :: find_if(seq.begin()、seq.end()、std :: bind2nd() 、val)) ' –
GrahamS