[TableGen] Add TreePatternNode::children and use it in for loops (NFC) (#119877)
[llvm-project.git] / libcxx / include / __cxx03 / __algorithm / unique.h
blobb7eb2849e4e37d0a17fde7d6046d3749210dd419
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___CXX03___ALGORITHM_UNIQUE_H
10 #define _LIBCPP___CXX03___ALGORITHM_UNIQUE_H
12 #include <__cxx03/__algorithm/adjacent_find.h>
13 #include <__cxx03/__algorithm/comp.h>
14 #include <__cxx03/__algorithm/iterator_operations.h>
15 #include <__cxx03/__config>
16 #include <__cxx03/__iterator/iterator_traits.h>
17 #include <__cxx03/__utility/move.h>
18 #include <__cxx03/__utility/pair.h>
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 # pragma GCC system_header
22 #endif
24 _LIBCPP_PUSH_MACROS
25 #include <__cxx03/__undef_macros>
27 _LIBCPP_BEGIN_NAMESPACE_STD
29 // unique
31 template <class _AlgPolicy, class _Iter, class _Sent, class _BinaryPredicate>
32 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 std::pair<_Iter, _Iter>
33 __unique(_Iter __first, _Sent __last, _BinaryPredicate&& __pred) {
34 __first = std::__adjacent_find(__first, __last, __pred);
35 if (__first != __last) {
36 // ... a a ? ...
37 // f i
38 _Iter __i = __first;
39 for (++__i; ++__i != __last;)
40 if (!__pred(*__first, *__i))
41 *++__first = _IterOps<_AlgPolicy>::__iter_move(__i);
42 ++__first;
43 return std::pair<_Iter, _Iter>(std::move(__first), std::move(__i));
45 return std::pair<_Iter, _Iter>(__first, __first);
48 template <class _ForwardIterator, class _BinaryPredicate>
49 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
50 unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred) {
51 return std::__unique<_ClassicAlgPolicy>(std::move(__first), std::move(__last), __pred).first;
54 template <class _ForwardIterator>
55 _LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
56 unique(_ForwardIterator __first, _ForwardIterator __last) {
57 return std::unique(__first, __last, __equal_to());
60 _LIBCPP_END_NAMESPACE_STD
62 _LIBCPP_POP_MACROS
64 #endif // _LIBCPP___CXX03___ALGORITHM_UNIQUE_H