Cpp-standard-library-cpp-algorithm-find-end
提供:Dev Guides
C ++アルゴリズムライブラリ-find_end()関数
説明
- C ++関数* std
- algorithm :: find_end()*は、要素の最後の出現を検索します。 比較のために `+ operator = +`を使用します。
宣言
- 以下は、std
- algorithmヘッダーからのstd :: algorithm :: find_end()関数の宣言です。
C 98
template <class ForwardIterator1, class ForwardIterator2>
ForwardIterator1 find_end(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
パラメーター
- first1 -イテレータを最初のシーケンスの初期位置に転送します。
- last1 -イテレータを最初のシーケンスの最終位置に転送します。
- first2 -イテレータを2番目のシーケンスの初期位置に転送します。
- last2 -イテレータを2番目のシーケンスの最終位置に転送します。
戻り値
`+ first1、last1 `で最後に出現する `(first2、last2)+`の最初の要素のイテレータを返します。
例外
要素比較またはイテレータの操作が例外をスローした場合、例外をスローします。
無効なパラメータは未定義の動作を引き起こすことに注意してください。
時間の複雑さ
リニア。
例
- 次の例は、std
- algorithm :: find_end()関数の使用法を示しています。
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void) {
vector<int> v1 = {1, 2, 1, 2, 1, 2};
vector<int> v2 = {1, 2};
auto result = find_end(v1.begin(), v1.end(), v2.begin(), v2.end());
if (result != v1.end())
cout << "Last sequence found at location "
<< distance(v1.begin(), result) << endl;
v2 = {1, 3};
result = find_end(v1.begin(), v1.end(), v2.begin(), v2.end());
if (result == v1.end())
cout << "Sequence doesn't present in vector." << endl;
return 0;
}
上記のプログラムをコンパイルして実行すると、次の結果が生成されます-
Last sequence found at location 4
Sequence doesn't present in vector.