std::list<T,Allocator>::unique
提供: cppreference.com
| (1) | ||
void unique(); |
(C++20未満) | |
size_type unique(); |
(C++20以上) | |
| (2) | ||
template< class BinaryPredicate > void unique( BinaryPredicate p ); |
(C++20未満) | |
template< class BinaryPredicate > size_type unique( BinaryPredicate p ); |
(C++20以上) | |
すべての連続する重複要素をコンテナから削除します。 等しい要素の各グループ内の最初の要素のみが残されます。 最初のバージョンは要素を比較するために operator== を使用し、2番目のバージョンは指定された二項述語 p を使用します。
引数
| p | - | 要素が等しいと扱われるべき場合に true を返す二項述語。 述語関数のシグネチャは以下と同等なものであるべきです。
シグネチャが |
戻り値
|
(なし) |
(C++20未満) |
|
削除された要素の数。 |
(C++20以上) |
計算量
コンテナのサイズに比例。
例
Run this code
#include <iostream>
#include <list>
int main()
{
std::list<int> x = {1, 2, 2, 3, 3, 2, 1, 1, 2};
std::cout << "contents before:";
for (auto val : x)
std::cout << ' ' << val;
std::cout << '\n';
x.unique();
std::cout << "contents after unique():";
for (auto val : x)
std::cout << ' ' << val;
std::cout << '\n';
return 0;
}
出力:
contents before: 1 2 2 3 3 2 1 1 2
contents after unique(): 1 2 3 2 1 2
関連項目
| 指定範囲の連続している重複要素を削除します (関数テンプレート) |