xref: /freebsd-src/contrib/llvm-project/libcxx/include/__algorithm/ranges_remove.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1753f127fSDimitry Andric //===----------------------------------------------------------------------===//
2753f127fSDimitry Andric //
3753f127fSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4753f127fSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5753f127fSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6753f127fSDimitry Andric //
7753f127fSDimitry Andric //===----------------------------------------------------------------------===//
8753f127fSDimitry Andric 
9753f127fSDimitry Andric #ifndef _LIBCPP___ALGORITHM_RANGES_REMOVE_H
10753f127fSDimitry Andric #define _LIBCPP___ALGORITHM_RANGES_REMOVE_H
11753f127fSDimitry Andric #include <__config>
12753f127fSDimitry Andric 
13753f127fSDimitry Andric #include <__algorithm/ranges_remove_if.h>
14753f127fSDimitry Andric #include <__functional/identity.h>
15753f127fSDimitry Andric #include <__functional/ranges_operations.h>
16753f127fSDimitry Andric #include <__iterator/concepts.h>
17753f127fSDimitry Andric #include <__iterator/permutable.h>
18753f127fSDimitry Andric #include <__iterator/projected.h>
19753f127fSDimitry Andric #include <__ranges/access.h>
20753f127fSDimitry Andric #include <__ranges/concepts.h>
21753f127fSDimitry Andric #include <__ranges/subrange.h>
22753f127fSDimitry Andric #include <__utility/move.h>
23753f127fSDimitry Andric 
24753f127fSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
25753f127fSDimitry Andric #  pragma GCC system_header
26753f127fSDimitry Andric #endif
27753f127fSDimitry Andric 
28b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS
29b3edf446SDimitry Andric #include <__undef_macros>
30b3edf446SDimitry Andric 
3106c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20
32753f127fSDimitry Andric 
33753f127fSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD
34753f127fSDimitry Andric 
35753f127fSDimitry Andric namespace ranges {
36753f127fSDimitry Andric namespace __remove {
37753f127fSDimitry Andric struct __fn {
38753f127fSDimitry Andric   template <permutable _Iter, sentinel_for<_Iter> _Sent, class _Type, class _Proj = identity>
39753f127fSDimitry Andric     requires indirect_binary_predicate<ranges::equal_to, projected<_Iter, _Proj>, const _Type*>
40*0fca6ea1SDimitry Andric   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
4106c3fb27SDimitry Andric   operator()(_Iter __first, _Sent __last, const _Type& __value, _Proj __proj = {}) const {
425f757f3fSDimitry Andric     auto __pred = [&](auto&& __other) -> bool { return __value == __other; };
43753f127fSDimitry Andric     return ranges::__remove_if_impl(std::move(__first), std::move(__last), __pred, __proj);
44753f127fSDimitry Andric   }
45753f127fSDimitry Andric 
46753f127fSDimitry Andric   template <forward_range _Range, class _Type, class _Proj = identity>
4706c3fb27SDimitry Andric     requires permutable<iterator_t<_Range>> &&
4806c3fb27SDimitry Andric              indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _Type*>
49*0fca6ea1SDimitry Andric   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
5006c3fb27SDimitry Andric   operator()(_Range&& __range, const _Type& __value, _Proj __proj = {}) const {
515f757f3fSDimitry Andric     auto __pred = [&](auto&& __other) -> bool { return __value == __other; };
52753f127fSDimitry Andric     return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
53753f127fSDimitry Andric   }
54753f127fSDimitry Andric };
55753f127fSDimitry Andric } // namespace __remove
56753f127fSDimitry Andric 
57753f127fSDimitry Andric inline namespace __cpo {
58753f127fSDimitry Andric inline constexpr auto remove = __remove::__fn{};
59753f127fSDimitry Andric } // namespace __cpo
60753f127fSDimitry Andric } // namespace ranges
61753f127fSDimitry Andric 
62753f127fSDimitry Andric _LIBCPP_END_NAMESPACE_STD
63753f127fSDimitry Andric 
6406c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20
65753f127fSDimitry Andric 
66b3edf446SDimitry Andric _LIBCPP_POP_MACROS
67b3edf446SDimitry Andric 
68753f127fSDimitry Andric #endif // _LIBCPP___ALGORITHM_RANGES_REMOVE_H
69