equal
二項述語で指定される等値または同等の要素で 2 個の span 要素をで比較します。
template<class InputIterator1, class InputIterator2>
bool equal(
InputIterator1 _First1,
InputIterator1 _Last1,
InputIterator2 _First2
);
template<class InputIterator1, class InputIterator2, class BinaryPredicate>
bool equal(
InputIterator1 _First1,
InputIterator1 _Last1,
InputIterator2 _First2,
BinaryPredicate _Comp
);
パラメーター
_First1
テストされる最初の範囲内の先頭の要素の位置を示す入力反復子。_Last1
テストされる最初の範囲の最後の要素の一つ前の 1 の位置を示す入力反復子。_First2
テストされる 2 番目の範囲内の先頭の要素の位置を示す入力反復子。_Comp
2 個の要素が等価として受け取る場合満たされている必要条件を定義するユーザー定義の述語関数オブジェクト。 二項述語は 2 つの引数を受け取り、条件が満たされている場合は true、満たされていない場合は false を返します。
戻り値
範囲が要素で二項述語で同じまたは等価と比較した要素の場合にのみtrue と; それ以外の場合は false。
解説
検索する範囲は有効である; すべてのポインターは dereferenceable なり、最後の位置は incrementation してプログラムからアクセスできます。
アルゴリズムの時間の複雑さは範囲に含まれている要素の数で直線的です。
要素間に等しいかどうかを確認するために使用される operator== がオペランド間の等価関係を課さなければ必要があります。
使用例
// alg_equal.cpp
// compile with: /EHsc
#include <vector>
#include <algorithm>
#include <iostream>
// Return whether second element is twice the first
bool twice ( int elem1, int elem2 )
{
return elem1 * 2 == elem2;
}
int main( )
{
using namespace std;
vector <int> v1, v2, v3;
vector <int>::iterator Iter1, Iter2, Iter3;
int i;
for ( i = 0 ; i <= 5 ; i++ )
{
v1.push_back( 5 * i );
}
int ii;
for ( ii = 0 ; ii <= 5 ; ii++ )
{
v2.push_back( 5 * ii );
}
int iii;
for ( iii = 0 ; iii <= 5 ; iii++ )
{
v3.push_back( 10 * iii );
}
cout << "v1 = ( " ;
for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
cout << *Iter1 << " ";
cout << ")" << endl;
cout << "v2 = ( " ;
for ( Iter2 = v2.begin( ) ; Iter2 != v2.end( ) ; Iter2++ )
cout << *Iter2 << " ";
cout << ")" << endl;
cout << "v3 = ( " ;
for ( Iter3 = v3.begin( ) ; Iter3 != v3.end( ) ; Iter3++ )
cout << *Iter3 << " ";
cout << ")" << endl;
// Testing v1 and v2 for equality under identity
bool b;
b = equal( v1.begin( ), v1.end( ), v2.begin( ) );
if ( b )
cout << "The vectors v1 and v2 are equal under equality."
<< endl;
else
cout << "The vectors v1 and v2 are not equal under equality."
<< endl;
// Testing v1 and v3 for equality under identity
bool c;
c = equal( v1.begin( ), v1.end( ), v3.begin( ) );
if ( c )
cout << "The vectors v1 and v3 are equal under equality."
<< endl;
else
cout << "The vectors v1 and v3 are not equal under equality."
<< endl;
// Testing v1 and v3 for equality under twice
bool d;
d = equal( v1.begin( ), v1.end( ), v3.begin( ), twice );
if ( d )
cout << "The vectors v1 and v3 are equal under twice."
<< endl;
else
cout << "The vectors v1 and v3 are not equal under twice."
<< endl;
}
必要条件
ヘッダー: <algorithm>
名前空間: std