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