23 Algorithms library [algorithms]

23.6 Mutating sequence operations [alg.modifying.operations]

23.6.9 Unique [alg.unique]

template<class ForwardIterator> constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last); template<class ExecutionPolicy, class ForwardIterator> ForwardIterator unique(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last); template<class ForwardIterator, class BinaryPredicate> constexpr ForwardIterator unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator, class BinaryPredicate> ForwardIterator unique(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
Requires: The comparison function shall be an equivalence relation.
The type of *first shall satisfy the Cpp17MoveAssignable requirements (Table 27).
Effects: For a nonempty range, eliminates all but the first element from every consecutive group of equivalent elements referred to by the iterator i in the range [first + 1, last) for which the following conditions hold: *(i - 1) == *i or pred(*(i - 1), *i) != false.
Returns: The end of the resulting range.
Complexity: For nonempty ranges, exactly (last - first) - 1 applications of the corresponding predicate.
template<class InputIterator, class OutputIterator> constexpr OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2> ForwardIterator2 unique_copy(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result); template<class InputIterator, class OutputIterator, class BinaryPredicate> constexpr OutputIterator unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred); template<class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2, class BinaryPredicate> ForwardIterator2 unique_copy(ExecutionPolicy&& exec, ForwardIterator1 first, ForwardIterator1 last, ForwardIterator2 result, BinaryPredicate pred);
Requires:
  • The comparison function shall be an equivalence relation.
  • The ranges [first, last) and [result, result+(last-first)) shall not overlap.
  • The expression *result = *first shall be valid.
  • For the overloads with no ExecutionPolicy, let T be the value type of InputIterator.
    If InputIterator meets the Cpp17ForwardIterator requirements, then there are no additional requirements for T.
    Otherwise, if OutputIterator meets the Cpp17ForwardIterator requirements and its value type is the same as T, then T shall be Cpp17CopyAssignable (Table 28).
    Otherwise, T shall be both Cpp17CopyConstructible (Table 26) and Cpp17CopyAssignable.
    [ Note
    :
    For the overloads with an ExecutionPolicy, there may be a performance cost if the value type of ForwardIterator1 is not both Cpp17CopyConstructible and Cpp17CopyAssignable.
    — end note
     ]
Effects: Copies only the first element from every consecutive group of equal elements referred to by the iterator i in the range [first, last) for which the following corresponding conditions hold: *i == *(i - 1) or pred(*i, *(i - 1)) != false.
Returns: The end of the resulting range.
Complexity: For nonempty ranges, exactly last - first - 1 applications of the corresponding predicate.