Warning: This file is not a C or C++ file. It does not have highlighting.
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 | //===----------------------------------------------------------------------===// |
8 | |
9 | #ifndef _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H |
10 | #define _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H |
11 | |
12 | #include <__algorithm/in_out_result.h> |
13 | #include <__algorithm/make_projected.h> |
14 | #include <__algorithm/remove_copy_if.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/projected.h> |
22 | #include <__ranges/access.h> |
23 | #include <__ranges/concepts.h> |
24 | #include <__ranges/dangling.h> |
25 | #include <__utility/forward.h> |
26 | #include <__utility/move.h> |
27 | |
28 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
29 | # pragma GCC system_header |
30 | #endif |
31 | |
32 | _LIBCPP_PUSH_MACROS |
33 | #include <__undef_macros> |
34 | |
35 | #if _LIBCPP_STD_VER >= 20 |
36 | |
37 | _LIBCPP_BEGIN_NAMESPACE_STD |
38 | |
39 | namespace ranges { |
40 | |
41 | template <class _InIter, class _OutIter> |
42 | using remove_copy_if_result = in_out_result<_InIter, _OutIter>; |
43 | |
44 | template <class _InIter, class _Sent, class _OutIter, class _Proj, class _Pred> |
45 | _LIBCPP_HIDE_FROM_ABI constexpr in_out_result<_InIter, _OutIter> |
46 | __remove_copy_if_impl(_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) { |
47 | for (; __first != __last; ++__first) { |
48 | if (!std::invoke(__pred, std::invoke(__proj, *__first))) { |
49 | *__result = *__first; |
50 | ++__result; |
51 | } |
52 | } |
53 | return {std::move(__first), std::move(__result)}; |
54 | } |
55 | |
56 | struct __remove_copy_if { |
57 | template <input_iterator _InIter, |
58 | sentinel_for<_InIter> _Sent, |
59 | weakly_incrementable _OutIter, |
60 | class _Proj = identity, |
61 | indirect_unary_predicate<projected<_InIter, _Proj>> _Pred> |
62 | requires indirectly_copyable<_InIter, _OutIter> |
63 | _LIBCPP_HIDE_FROM_ABI constexpr remove_copy_if_result<_InIter, _OutIter> |
64 | operator()(_InIter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const { |
65 | return ranges::__remove_copy_if_impl(std::move(__first), std::move(__last), std::move(__result), __pred, __proj); |
66 | } |
67 | |
68 | template <input_range _Range, |
69 | weakly_incrementable _OutIter, |
70 | class _Proj = identity, |
71 | indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred> |
72 | requires indirectly_copyable<iterator_t<_Range>, _OutIter> |
73 | _LIBCPP_HIDE_FROM_ABI constexpr remove_copy_if_result<borrowed_iterator_t<_Range>, _OutIter> |
74 | operator()(_Range&& __range, _OutIter __result, _Pred __pred, _Proj __proj = {}) const { |
75 | return ranges::__remove_copy_if_impl( |
76 | ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __proj); |
77 | } |
78 | }; |
79 | |
80 | inline namespace __cpo { |
81 | inline constexpr auto remove_copy_if = __remove_copy_if{}; |
82 | } // namespace __cpo |
83 | } // namespace ranges |
84 | |
85 | _LIBCPP_END_NAMESPACE_STD |
86 | |
87 | #endif // _LIBCPP_STD_VER >= 20 |
88 | |
89 | _LIBCPP_POP_MACROS |
90 | |
91 | #endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_COPY_IF_H |
92 |
Warning: This file is not a C or C++ file. It does not have highlighting.