File indexing completed on 2026-05-03 08:13:20
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LIBCPP___CXX03___ALGORITHM_RANGES_REPLACE_COPY_IF_H
0010 #define _LIBCPP___CXX03___ALGORITHM_RANGES_REPLACE_COPY_IF_H
0011
0012 #include <__cxx03/__algorithm/in_out_result.h>
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__functional/identity.h>
0015 #include <__cxx03/__functional/invoke.h>
0016 #include <__cxx03/__iterator/concepts.h>
0017 #include <__cxx03/__iterator/projected.h>
0018 #include <__cxx03/__ranges/access.h>
0019 #include <__cxx03/__ranges/concepts.h>
0020 #include <__cxx03/__ranges/dangling.h>
0021 #include <__cxx03/__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 <__cxx03/__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 namespace __replace_copy_if {
0056
0057 struct __fn {
0058 template <input_iterator _InIter,
0059 sentinel_for<_InIter> _Sent,
0060 class _Type,
0061 output_iterator<const _Type&> _OutIter,
0062 class _Proj = identity,
0063 indirect_unary_predicate<projected<_InIter, _Proj>> _Pred>
0064 requires indirectly_copyable<_InIter, _OutIter>
0065 _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<_InIter, _OutIter> operator()(
0066 _InIter __first, _Sent __last, _OutIter __result, _Pred __pred, const _Type& __new_value, _Proj __proj = {})
0067 const {
0068 return ranges::__replace_copy_if_impl(
0069 std::move(__first), std::move(__last), std::move(__result), __pred, __new_value, __proj);
0070 }
0071
0072 template <input_range _Range,
0073 class _Type,
0074 output_iterator<const _Type&> _OutIter,
0075 class _Proj = identity,
0076 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
0077 requires indirectly_copyable<iterator_t<_Range>, _OutIter>
0078 _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_if_result<borrowed_iterator_t<_Range>, _OutIter>
0079 operator()(_Range&& __range, _OutIter __result, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const {
0080 return ranges::__replace_copy_if_impl(
0081 ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __new_value, __proj);
0082 }
0083 };
0084
0085 }
0086
0087 inline namespace __cpo {
0088 inline constexpr auto replace_copy_if = __replace_copy_if::__fn{};
0089 }
0090 }
0091
0092 _LIBCPP_END_NAMESPACE_STD
0093
0094 #endif
0095
0096 _LIBCPP_POP_MACROS
0097
0098 #endif