[rtsan] Remove mkfifoat interceptor (#116997)
[llvm-project.git] / libcxx / include / __cxx03 / __algorithm / ranges_unique_copy.h
blobc30332a217f7ee9608e6d444521dd8f36c7dc295
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___ALGORITHM_RANGES_UNIQUE_COPY_H
10 #define _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H
12 #include <__cxx03/__algorithm/in_out_result.h>
13 #include <__cxx03/__algorithm/iterator_operations.h>
14 #include <__cxx03/__algorithm/make_projected.h>
15 #include <__cxx03/__algorithm/unique_copy.h>
16 #include <__cxx03/__concepts/same_as.h>
17 #include <__cxx03/__config>
18 #include <__cxx03/__functional/identity.h>
19 #include <__cxx03/__functional/invoke.h>
20 #include <__cxx03/__functional/ranges_operations.h>
21 #include <__cxx03/__iterator/concepts.h>
22 #include <__cxx03/__iterator/iterator_traits.h>
23 #include <__cxx03/__iterator/projected.h>
24 #include <__cxx03/__ranges/access.h>
25 #include <__cxx03/__ranges/concepts.h>
26 #include <__cxx03/__ranges/dangling.h>
27 #include <__cxx03/__utility/forward.h>
28 #include <__cxx03/__utility/move.h>
29 #include <__cxx03/__utility/pair.h>
31 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
32 # pragma GCC system_header
33 #endif
35 _LIBCPP_PUSH_MACROS
36 #include <__cxx03/__undef_macros>
38 #if _LIBCPP_STD_VER >= 20
40 _LIBCPP_BEGIN_NAMESPACE_STD
42 namespace ranges {
44 template <class _InIter, class _OutIter>
45 using unique_copy_result = in_out_result<_InIter, _OutIter>;
47 namespace __unique_copy {
49 template <class _InIter, class _OutIter>
50 concept __can_reread_from_output = (input_iterator<_OutIter> && same_as<iter_value_t<_InIter>, iter_value_t<_OutIter>>);
52 struct __fn {
53 template <class _InIter, class _OutIter>
54 static consteval auto __get_algo_tag() {
55 if constexpr (forward_iterator<_InIter>) {
56 return __unique_copy_tags::__reread_from_input_tag{};
57 } else if constexpr (__can_reread_from_output<_InIter, _OutIter>) {
58 return __unique_copy_tags::__reread_from_output_tag{};
59 } else if constexpr (indirectly_copyable_storable<_InIter, _OutIter>) {
60 return __unique_copy_tags::__read_from_tmp_value_tag{};
64 template <class _InIter, class _OutIter>
65 using __algo_tag_t = decltype(__get_algo_tag<_InIter, _OutIter>());
67 template <input_iterator _InIter,
68 sentinel_for<_InIter> _Sent,
69 weakly_incrementable _OutIter,
70 class _Proj = identity,
71 indirect_equivalence_relation<projected<_InIter, _Proj>> _Comp = ranges::equal_to>
72 requires indirectly_copyable<_InIter, _OutIter> &&
73 (forward_iterator<_InIter> ||
74 (input_iterator<_OutIter> && same_as<iter_value_t<_InIter>, iter_value_t<_OutIter>>) ||
75 indirectly_copyable_storable<_InIter, _OutIter>)
76 _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result<_InIter, _OutIter>
77 operator()(_InIter __first, _Sent __last, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const {
78 auto __ret = std::__unique_copy<_RangeAlgPolicy>(
79 std::move(__first),
80 std::move(__last),
81 std::move(__result),
82 std::__make_projected(__comp, __proj),
83 __algo_tag_t<_InIter, _OutIter>());
84 return {std::move(__ret.first), std::move(__ret.second)};
87 template <input_range _Range,
88 weakly_incrementable _OutIter,
89 class _Proj = identity,
90 indirect_equivalence_relation<projected<iterator_t<_Range>, _Proj>> _Comp = ranges::equal_to>
91 requires indirectly_copyable<iterator_t<_Range>, _OutIter> &&
92 (forward_iterator<iterator_t<_Range>> ||
93 (input_iterator<_OutIter> && same_as<range_value_t<_Range>, iter_value_t<_OutIter>>) ||
94 indirectly_copyable_storable<iterator_t<_Range>, _OutIter>)
95 _LIBCPP_HIDE_FROM_ABI constexpr unique_copy_result<borrowed_iterator_t<_Range>, _OutIter>
96 operator()(_Range&& __range, _OutIter __result, _Comp __comp = {}, _Proj __proj = {}) const {
97 auto __ret = std::__unique_copy<_RangeAlgPolicy>(
98 ranges::begin(__range),
99 ranges::end(__range),
100 std::move(__result),
101 std::__make_projected(__comp, __proj),
102 __algo_tag_t<iterator_t<_Range>, _OutIter>());
103 return {std::move(__ret.first), std::move(__ret.second)};
107 } // namespace __unique_copy
109 inline namespace __cpo {
110 inline constexpr auto unique_copy = __unique_copy::__fn{};
111 } // namespace __cpo
112 } // namespace ranges
114 _LIBCPP_END_NAMESPACE_STD
116 #endif // _LIBCPP_STD_VER >= 20
118 _LIBCPP_POP_MACROS
120 #endif // _LIBCPP___ALGORITHM_RANGES_UNIQUE_COPY_H