المتغيرات
فضاءات التسمية
أفعال

std::{{{1}}}::unique

من cppreference.com
void unique();
(1) قالب:mark since none
template< class BinaryPredicate >
void unique( BinaryPredicate p );
(2) قالب:mark since none

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‎.

محتويات

[تعديل] Parameters

قالب:par pred2 eq

[تعديل] Return value

(none)

[تعديل] Complexity

Linear in the size of the container

[تعديل] Example

#include <iostream>
#include <{{{1}}}>
 
int main()
{
  std::{{{1}}}<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

[تعديل] See also

قالب:dsc tfun