blob: 9e05c09fe5ee890d5f7f67c315cdf98ad307d56a [file] [log] [blame]
Kaido Kert788710a2023-06-05 07:50:22 -07001//===----------------------------------------------------------------------===//
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//===----------------------------------------------------------------------===//
8
9#ifndef _LIBCPP___ALGORITHM_RANGES_UNIQUE_H
10#define _LIBCPP___ALGORITHM_RANGES_UNIQUE_H
11
12#include <__algorithm/iterator_operations.h>
13#include <__algorithm/make_projected.h>
14#include <__algorithm/unique.h>
15#include <__config>
16#include <__functional/identity.h>
17#include <__functional/invoke.h>
18#include <__functional/ranges_operations.h>
19#include <__iterator/concepts.h>
20#include <__iterator/iterator_traits.h>
21#include <__iterator/permutable.h>
22#include <__iterator/projected.h>
23#include <__ranges/access.h>
24#include <__ranges/concepts.h>
25#include <__ranges/dangling.h>
26#include <__ranges/subrange.h>
27#include <__utility/forward.h>
28#include <__utility/move.h>
29#include <__utility/pair.h>
30
31#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32# pragma GCC system_header
33#endif
34
Kaido Kert56d7c4e2024-04-13 12:59:27 -070035#if _LIBCPP_STD_VER >= 20
Kaido Kert788710a2023-06-05 07:50:22 -070036
37_LIBCPP_BEGIN_NAMESPACE_STD
38
39namespace ranges {
40namespace __unique {
41
42 struct __fn {
43 template <
44 permutable _Iter,
45 sentinel_for<_Iter> _Sent,
46 class _Proj = identity,
47 indirect_equivalence_relation<projected<_Iter, _Proj>> _Comp = ranges::equal_to>
48 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
49 operator()(_Iter __first, _Sent __last, _Comp __comp = {}, _Proj __proj = {}) const {
50 auto __ret = std::__unique<_RangeAlgPolicy>(
51 std::move(__first), std::move(__last), std::__make_projected(__comp, __proj));
52 return {std::move(__ret.first), std::move(__ret.second)};
53 }
54
55 template <
56 forward_range _Range,
57 class _Proj = identity,
58 indirect_equivalence_relation<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
59 requires permutable<iterator_t<_Range>>
60 _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
61 operator()(_Range&& __range, _Comp __comp = {}, _Proj __proj = {}) const {
62 auto __ret = std::__unique<_RangeAlgPolicy>(
63 ranges::begin(__range), ranges::end(__range), std::__make_projected(__comp, __proj));
64 return {std::move(__ret.first), std::move(__ret.second)};
65 }
66 };
67
68} // namespace __unique
69
70inline namespace __cpo {
71 inline constexpr auto unique = __unique::__fn{};
72} // namespace __cpo
73} // namespace ranges
74
75_LIBCPP_END_NAMESPACE_STD
76
Kaido Kert56d7c4e2024-04-13 12:59:27 -070077#endif // _LIBCPP_STD_VER >= 20
Kaido Kert788710a2023-06-05 07:50:22 -070078
79#endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_H