std::forward_list::unique
提供:cppreference.com
< cpp | container | forward list
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| void unique(); |
(1) | (C + + 11以来) |
| template< class BinaryPredicate > void unique( BinaryPredicate p ); |
(2) | (C + + 11以来) |
コンテナからすべて'連続した重複要素を削除します。等しい要素の各グループ内の最初の要素だけが残っている。最初のバージョンは、要素を比較する
operator==使用して、2番目のバージョンは、指定されたバイナリ述語pを使用しています.Original:
Removes all consecutive duplicate elements from the container. Only the first element in each group of equal elements is left. The first version uses
operator== to compare the elements, the second version uses the given binary predicate p.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
目次 |
[編集] パラメータ
| p | - | binary predicate which returns true if the elements should be treated as equal. The signature of the predicate function should be equivalent to the following:
The signature does not need to have const &, but the function must not modify the objects passed to it. | |||||||||
[編集] 値を返します
(なし)
Original:
(none)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集] 複雑
容器の大きさに比例
Original:
Linear in the size of the container
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集] 例
#include <iostream> #include <forward_list> int main() { std::forward_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; }
Output:
contents before: 1 2 2 3 3 2 1 1 2 contents after unique(): 1 2 3 2 1 2
[編集] も参照してください
| removes consecutive duplicate elements in a range (関数テンプレート) | |