Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:12

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___ALGORITHM_UNIQUE_H
0010 #define _LIBCPP___ALGORITHM_UNIQUE_H
0011 
0012 #include <__algorithm/adjacent_find.h>
0013 #include <__algorithm/comp.h>
0014 #include <__algorithm/iterator_operations.h>
0015 #include <__config>
0016 #include <__functional/identity.h>
0017 #include <__iterator/iterator_traits.h>
0018 #include <__utility/move.h>
0019 #include <__utility/pair.h>
0020 
0021 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0022 #  pragma GCC system_header
0023 #endif
0024 
0025 _LIBCPP_PUSH_MACROS
0026 #include <__undef_macros>
0027 
0028 _LIBCPP_BEGIN_NAMESPACE_STD
0029 
0030 // unique
0031 
0032 template <class _AlgPolicy, class _Iter, class _Sent, class _BinaryPredicate>
0033 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 std::pair<_Iter, _Iter>
0034 __unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
0035   __identity __proj;
0036   __first = std::__adjacent_find(__first, __last, __pred, __proj);
0037   if (__first != __last) {
0038     // ...  a  a  ?  ...
0039     //      f     i
0040     _Iter __i = __first;
0041     for (++__i; ++__i != __last;)
0042       if (!__pred(*__first, *__i))
0043         *++__first = _IterOps<_AlgPolicy>::__iter_move(__i);
0044     ++__first;
0045     return std::pair<_Iter, _Iter>(std::move(__first), std::move(__i));
0046   }
0047   return std::pair<_Iter, _Iter>(__first, __first);
0048 }
0049 
0050 template <class _ForwardIterator, class _BinaryPredicate>
0051 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
0052 unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
0053   return std::__unique<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred).first;
0054 }
0055 
0056 template <class _ForwardIterator>
0057 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
0058 unique(_ForwardIterator __first, _ForwardIterator __last) {
0059   return std::unique(__first, __last, __equal_to());
0060 }
0061 
0062 _LIBCPP_END_NAMESPACE_STD
0063 
0064 _LIBCPP_POP_MACROS
0065 
0066 #endif // _LIBCPP___ALGORITHM_UNIQUE_H