AMDGPU: Fix verifier assert with out of bounds subregister indexes (#119799)
[llvm-project.git] / libcxx / include / __cxx03 / __algorithm / ranges_replace_if.h
blob499cc7887b16c125a3d686f8e435f3ba2f289ac6
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #ifndef _LIBCPP___CXX03___ALGORITHM_RANGES_REPLACE_IF_H
10 #define _LIBCPP___CXX03___ALGORITHM_RANGES_REPLACE_IF_H
12 #include <__cxx03/__config>
13 #include <__cxx03/__functional/identity.h>
14 #include <__cxx03/__functional/invoke.h>
15 #include <__cxx03/__iterator/concepts.h>
16 #include <__cxx03/__iterator/projected.h>
17 #include <__cxx03/__ranges/access.h>
18 #include <__cxx03/__ranges/concepts.h>
19 #include <__cxx03/__ranges/dangling.h>
20 #include <__cxx03/__utility/move.h>
22 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
23 # pragma GCC system_header
24 #endif
26 _LIBCPP_PUSH_MACROS
27 #include <__cxx03/__undef_macros>
29 #if _LIBCPP_STD_VER >= 20
31 _LIBCPP_BEGIN_NAMESPACE_STD
33 namespace ranges {
35 template <class _Iter, class _Sent, class _Type, class _Proj, class _Pred>
36 _LIBCPP_HIDE_FROM_ABI constexpr _Iter
37 __replace_if_impl(_Iter __first, _Sent __last, _Pred& __pred, const _Type& __new_value, _Proj& __proj) {
38 for (; __first != __last; ++__first) {
39 if (std::invoke(__pred, std::invoke(__proj, *__first)))
40 *__first = __new_value;
42 return __first;
45 namespace __replace_if {
46 struct __fn {
47 template <input_iterator _Iter,
48 sentinel_for<_Iter> _Sent,
49 class _Type,
50 class _Proj = identity,
51 indirect_unary_predicate<projected<_Iter, _Proj>> _Pred>
52 requires indirectly_writable<_Iter, const _Type&>
53 _LIBCPP_HIDE_FROM_ABI constexpr _Iter
54 operator()(_Iter __first, _Sent __last, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const {
55 return ranges::__replace_if_impl(std::move(__first), std::move(__last), __pred, __new_value, __proj);
58 template <input_range _Range,
59 class _Type,
60 class _Proj = identity,
61 indirect_unary_predicate<projected<iterator_t<_Range>, _Proj>> _Pred>
62 requires indirectly_writable<iterator_t<_Range>, const _Type&>
63 _LIBCPP_HIDE_FROM_ABI constexpr borrowed_iterator_t<_Range>
64 operator()(_Range&& __range, _Pred __pred, const _Type& __new_value, _Proj __proj = {}) const {
65 return ranges::__replace_if_impl(ranges::begin(__range), ranges::end(__range), __pred, __new_value, __proj);
68 } // namespace __replace_if
70 inline namespace __cpo {
71 inline constexpr auto replace_if = __replace_if::__fn{};
72 } // namespace __cpo
73 } // namespace ranges
75 _LIBCPP_END_NAMESPACE_STD
77 #endif // _LIBCPP_STD_VER >= 20
79 _LIBCPP_POP_MACROS
81 #endif // _LIBCPP___CXX03___ALGORITHM_RANGES_REPLACE_IF_H