Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:20

0001 //===----------------------------------------------------------------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_RANGES_REMOVE_IF_H
0010 #define _LIBCPP___CXX03___ALGORITHM_RANGES_REMOVE_IF_H
0011 #include <__cxx03/__config>
0012 
0013 #include <__cxx03/__algorithm/ranges_find_if.h>
0014 #include <__cxx03/__functional/identity.h>
0015 #include <__cxx03/__functional/invoke.h>
0016 #include <__cxx03/__functional/ranges_operations.h>
0017 #include <__cxx03/__iterator/concepts.h>
0018 #include <__cxx03/__iterator/iter_move.h>
0019 #include <__cxx03/__iterator/permutable.h>
0020 #include <__cxx03/__iterator/projected.h>
0021 #include <__cxx03/__ranges/access.h>
0022 #include <__cxx03/__ranges/concepts.h>
0023 #include <__cxx03/__ranges/subrange.h>
0024 #include <__cxx03/__utility/move.h>
0025 
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 #  pragma GCC system_header
0028 #endif
0029 
0030 _LIBCPP_PUSH_MACROS
0031 #include <__cxx03/__undef_macros>
0032 
0033 #if _LIBCPP_STD_VER >= 20
0034 
0035 _LIBCPP_BEGIN_NAMESPACE_STD
0036 
0037 namespace ranges {
0038 
0039 template <class _Iter, class _Sent, class _Proj, class _Pred>
0040 _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
0041 __remove_if_impl(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
0042   auto __new_end = ranges::__find_if_impl(__first, __last, __pred, __proj);
0043   if (__new_end == __last)
0044     return {__new_end, __new_end};
0045 
0046   _Iter __i = __new_end;
0047   while (++__i != __last) {
0048     if (!std::invoke(__pred, std::invoke(__proj, *__i))) {
0049       *__new_end = ranges::iter_move(__i);
0050       ++__new_end;
0051     }
0052   }
0053   return {__new_end, __i};
0054 }
0055 
0056 namespace __remove_if {
0057 struct __fn {
0058   template <permutable _Iter,
0059             sentinel_for<_Iter> _Sent,
0060             class _Proj = identity,
0061             indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
0062   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange<_Iter>
0063   operator()(_Iter __first, _Sent __last, _Pred __pred, _Proj __proj = {}) const {
0064     return ranges::__remove_if_impl(std::move(__first), std::move(__last), __pred, __proj);
0065   }
0066 
0067   template <forward_range _Range,
0068             class _Proj = identity,
0069             indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
0070     requires permutable<iterator_t<_Range>>
0071   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr borrowed_subrange_t<_Range>
0072   operator()(_Range&& __range, _Pred __pred, _Proj __proj = {}) const {
0073     return ranges::__remove_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __proj);
0074   }
0075 };
0076 } // namespace __remove_if
0077 
0078 inline namespace __cpo {
0079 inline constexpr auto remove_if = __remove_if::__fn{};
0080 } // namespace __cpo
0081 } // namespace ranges
0082 
0083 _LIBCPP_END_NAMESPACE_STD
0084 
0085 #endif // _LIBCPP_STD_VER >= 20
0086 
0087 _LIBCPP_POP_MACROS
0088 
0089 #endif // _LIBCPP___CXX03___ALGORITHM_RANGES_REMOVE_IF_H