Cpp-standard-library-cpp-algorithm-find-if-not
提供:Dev Guides
C ++アルゴリズムライブラリ-find_if_not()関数
説明
- C ++関数* std
- algorithm :: find_if_not()*は、条件を満たす要素の最後の出現を検索します。 条件を指定するために `+ unary predicate +`を使用します。
宣言
- 以下は、std
- algorithmヘッダーからのstd :: algorithm :: find_if_not()関数の宣言です。
C 11
template <class InputIterator, class UnaryPredicate>
InputIterator find_if_not(InputIterator first, InputIterator last, UnaryPredicate pred);
パラメーター
- first -イテレータを初期位置に入力します。
- last -最終位置への最終イテレータ。
- pred -1つの引数を受け入れ、boolを返す単項述語。
戻り値
は、 `+ unary predicate `がfalseを返す範囲 `(first、last)+`の最初の要素への反復子を返します。 そのような要素が見つからない場合、関数は最後を返します。
例外
述語またはイテレータの操作が例外をスローした場合、例外をスローします。
無効なパラメータは未定義の動作を引き起こすことに注意してください。
時間の複雑さ
リニア。
例
- 次の例は、std
- algorithm :: find_if_not()関数の使用法を示しています。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool unary_pred(int n) {
return ((n % 2) == 0);
}
int main(void) {
vector<int> v = {2, 4, 61, 8, 10};
auto it = find_if_not(v.begin(), v.end(), unary_pred);
if (it != end(v))
cout << "First odd number is " << *it << endl;
v = {2, 4, 6, 8, 10};
it = find_if_not(v.begin(), v.end(), unary_pred);
if (it == end(v))
cout << "Only enven elements present in the sequence." << endl;
return 0;
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
First odd number is 61
Only enven elements present in the sequence.