find_if

シーケンスから指定した条件を満たす最初の要素を見つけます。

ソートされていないシーケンスでも有効に機能します。

find_if のサンプルコード

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

bool comp(char ch) {
  return ch > 'M' ? true : false;
}

int main() {
  vector<char> v;
  vector<char>::iterator i;

  for (int j = 0; j < 26; j++) {
    v.push_back('A' + j);
  }

  i = find_if(v.begin(), v.end(), comp);

  while (i != v.end()) {
    cout << *i;
    ++i;
  }
  cout << endl;

  return 0;
}

実行結果は次の通りです。

./a.out
NOPQRSTUVWXYZ

比較条件が関数 comp で指定したように 'M' より大きな (コードの) 文字です。このため N から始まる箇所が結果として返されています。