list::unique
移除符合從 清單中的某個其他二進位述詞的相鄰複製項目或相鄰項目。
void unique( );
template<class BinaryPredicate>
void unique(
BinaryPredicate _Pred
);
參數
- _Pred
用於的二進位述詞比較連續項目。
備註
這個函式採用,清單中排序,因此,所有重複項目為相鄰的。不是相鄰的複本不會被刪除。
第 10% 成員函式中等於其前一個項目中的每個項目。
第二 + 成成員函式中使用它前面的項目比較,滿足述詞函式 _Pred 的每一個項目。您可以在 **<functional>**標頭可用於宣告的任何一個二進位物件。_Pred 函式的引數或建立擁有。
範例
// list_unique.cpp
// compile with: /EHsc
#include <list>
#include <iostream>
int main( )
{
using namespace std;
list <int> c1;
list <int>::iterator c1_Iter, c2_Iter,c3_Iter;
not_equal_to<int> mypred;
c1.push_back( -10 );
c1.push_back( 10 );
c1.push_back( 10 );
c1.push_back( 20 );
c1.push_back( 20 );
c1.push_back( -10 );
cout << "The initial list is c1 =";
for ( c1_Iter = c1.begin( ); c1_Iter != c1.end( ); c1_Iter++ )
cout << " " << *c1_Iter;
cout << endl;
list <int> c2 = c1;
c2.unique( );
cout << "After removing successive duplicate elements, c2 =";
for ( c2_Iter = c2.begin( ); c2_Iter != c2.end( ); c2_Iter++ )
cout << " " << *c2_Iter;
cout << endl;
list <int> c3 = c2;
c3.unique( mypred );
cout << "After removing successive unequal elements, c3 =";
for ( c3_Iter = c3.begin( ); c3_Iter != c3.end( ); c3_Iter++ )
cout << " " << *c3_Iter;
cout << endl;
}
需求
標題: <list>
命名空間: std