Back to home page

EIC code displayed by LXR

 
 

    


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

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___ALGORITHM_RANGES_REPLACE_COPY_IF_H
0010 #define _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H
0011 
0012 #include <__algorithm/in_out_result.h>
0013 #include <__config>
0014 #include <__functional/identity.h>
0015 #include <__functional/invoke.h>
0016 #include <__iterator/concepts.h>
0017 #include <__iterator/projected.h>
0018 #include <__ranges/access.h>
0019 #include <__ranges/concepts.h>
0020 #include <__ranges/dangling.h>
0021 #include <__utility/move.h>
0022 
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 #  pragma GCC system_header
0025 #endif
0026 
0027 _LIBCPP_PUSH_MACROS
0028 #include <__undef_macros>
0029 
0030 #if _LIBCPP_STD_VER >= 20
0031 
0032 _LIBCPP_BEGIN_NAMESPACE_STD
0033 
0034 namespace ranges {
0035 
0036 template <class _InIter, class _OutIter>
0037 using replace_copy_if_result = in_out_result<_InIter, _OutIter>;
0038 
0039 template <class _InIter, class _Sent, class _OutIter, class _Pred, class _Type, class _Proj>
0040 _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<_InIter, _OutIter> __replace_copy_if_impl(
0041     _InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, const _Type& __new_value, _Proj& __proj) {
0042   while (__first != __last) {
0043     if (std::invoke(__pred, std::invoke(__proj, *__first)))
0044       *__result = __new_value;
0045     else
0046       *__result = *__first;
0047 
0048     ++__first;
0049     ++__result;
0050   }
0051 
0052   return {std::move(__first), std::move(__result)};
0053 }
0054 
0055 struct __replace_copy_if {
0056   template <input_iterator _InIter,
0057             sentinel_for<_InIter> _Sent,
0058             class _Type,
0059             output_iterator<const _Type&> _OutIter,
0060             class _Proj = identity,
0061             indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
0062     requires indirectly_copyable<_InIter, _OutIter>
0063   _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<_InIter, _OutIter> operator()(
0064       _InIter __first, _Sent __last, _OutIter __result, _Pred __pred, const _Type& __new_value, _Proj __proj = {})
0065       const {
0066     return ranges::__replace_copy_if_impl(
0067         std::move(__first), std::move(__last), std::move(__result), __pred, __new_value, __proj);
0068   }
0069 
0070   template <input_range _Range,
0071             class _Type,
0072             output_iterator<const _Type&> _OutIter,
0073             class _Proj = identity,
0074             indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
0075     requires indirectly_copyable<iterator_t<_Range>, _OutIter>
0076   _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
0077   operator()(_Range&& __range, _OutIter __result, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const {
0078     return ranges::__replace_copy_if_impl(
0079         ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __new_value, __proj);
0080   }
0081 };
0082 
0083 inline namespace __cpo {
0084 inline constexpr auto replace_copy_if = __replace_copy_if{};
0085 } // namespace __cpo
0086 } // namespace ranges
0087 
0088 _LIBCPP_END_NAMESPACE_STD
0089 
0090 #endif // _LIBCPP_STD_VER >= 20
0091 
0092 _LIBCPP_POP_MACROS
0093 
0094 #endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_IF_H