1753f127fSDimitry Andric //===----------------------------------------------------------------------===// 2753f127fSDimitry Andric // 3753f127fSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4753f127fSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5753f127fSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6753f127fSDimitry Andric // 7753f127fSDimitry Andric //===----------------------------------------------------------------------===// 8753f127fSDimitry Andric 9753f127fSDimitry Andric #ifndef _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H 10753f127fSDimitry Andric #define _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H 11753f127fSDimitry Andric 12753f127fSDimitry Andric #include <__algorithm/in_out_result.h> 1361cfbce3SDimitry Andric #include <__algorithm/ranges_replace_copy_if.h> 14753f127fSDimitry Andric #include <__config> 15753f127fSDimitry Andric #include <__functional/identity.h> 16753f127fSDimitry Andric #include <__functional/invoke.h> 17753f127fSDimitry Andric #include <__functional/ranges_operations.h> 18753f127fSDimitry Andric #include <__iterator/concepts.h> 19753f127fSDimitry Andric #include <__iterator/projected.h> 20753f127fSDimitry Andric #include <__ranges/access.h> 21753f127fSDimitry Andric #include <__ranges/concepts.h> 22753f127fSDimitry Andric #include <__ranges/dangling.h> 23753f127fSDimitry Andric #include <__utility/move.h> 24753f127fSDimitry Andric 25753f127fSDimitry Andric #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 26753f127fSDimitry Andric # pragma GCC system_header 27753f127fSDimitry Andric #endif 28753f127fSDimitry Andric 29*b3edf446SDimitry Andric _LIBCPP_PUSH_MACROS 30*b3edf446SDimitry Andric #include <__undef_macros> 31*b3edf446SDimitry Andric 3206c3fb27SDimitry Andric #if _LIBCPP_STD_VER >= 20 33753f127fSDimitry Andric 34753f127fSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 35753f127fSDimitry Andric 36753f127fSDimitry Andric namespace ranges { 37753f127fSDimitry Andric 38753f127fSDimitry Andric template <class _InIter, class _OutIter> 39753f127fSDimitry Andric using replace_copy_result = in_out_result<_InIter, _OutIter>; 40753f127fSDimitry Andric 41753f127fSDimitry Andric namespace __replace_copy { 42753f127fSDimitry Andric 43753f127fSDimitry Andric struct __fn { 4461cfbce3SDimitry Andric template <input_iterator _InIter, 4561cfbce3SDimitry Andric sentinel_for<_InIter> _Sent, 4661cfbce3SDimitry Andric class _OldType, 4761cfbce3SDimitry Andric class _NewType, 4861cfbce3SDimitry Andric output_iterator<const _NewType&> _OutIter, 4961cfbce3SDimitry Andric class _Proj = identity> 50753f127fSDimitry Andric requires indirectly_copyable<_InIter, _OutIter> && 5161cfbce3SDimitry Andric indirect_binary_predicate<ranges::equal_to, projected<_InIter, _Proj>, const _OldType*> 5261cfbce3SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_result<_InIter, _OutIter> operator__fn5361cfbce3SDimitry Andric operator()(_InIter __first, 5461cfbce3SDimitry Andric _Sent __last, 5561cfbce3SDimitry Andric _OutIter __result, 5661cfbce3SDimitry Andric const _OldType& __old_value, 5761cfbce3SDimitry Andric const _NewType& __new_value, 58753f127fSDimitry Andric _Proj __proj = {}) const { 595f757f3fSDimitry Andric auto __pred = [&](const auto& __value) -> bool { return __value == __old_value; }; 6061cfbce3SDimitry Andric return ranges::__replace_copy_if_impl( 6161cfbce3SDimitry Andric std::move(__first), std::move(__last), std::move(__result), __pred, __new_value, __proj); 62753f127fSDimitry Andric } 63753f127fSDimitry Andric 6461cfbce3SDimitry Andric template <input_range _Range, 6561cfbce3SDimitry Andric class _OldType, 6661cfbce3SDimitry Andric class _NewType, 6761cfbce3SDimitry Andric output_iterator<const _NewType&> _OutIter, 68753f127fSDimitry Andric class _Proj = identity> 69753f127fSDimitry Andric requires indirectly_copyable<iterator_t<_Range>, _OutIter> && 7061cfbce3SDimitry Andric indirect_binary_predicate<ranges::equal_to, projected<iterator_t<_Range>, _Proj>, const _OldType*> operator__fn7106c3fb27SDimitry Andric _LIBCPP_HIDE_FROM_ABI constexpr replace_copy_result<borrowed_iterator_t<_Range>, _OutIter> operator()( 7206c3fb27SDimitry Andric _Range&& __range, _OutIter __result, const _OldType& __old_value, const _NewType& __new_value, _Proj __proj = {}) 7306c3fb27SDimitry Andric const { 745f757f3fSDimitry Andric auto __pred = [&](const auto& __value) -> bool { return __value == __old_value; }; 7561cfbce3SDimitry Andric return ranges::__replace_copy_if_impl( 7661cfbce3SDimitry Andric ranges::begin(__range), ranges::end(__range), std::move(__result), __pred, __new_value, __proj); 77753f127fSDimitry Andric } 78753f127fSDimitry Andric }; 79753f127fSDimitry Andric 80753f127fSDimitry Andric } // namespace __replace_copy 81753f127fSDimitry Andric 82753f127fSDimitry Andric inline namespace __cpo { 83753f127fSDimitry Andric inline constexpr auto replace_copy = __replace_copy::__fn{}; 84753f127fSDimitry Andric } // namespace __cpo 85753f127fSDimitry Andric } // namespace ranges 86753f127fSDimitry Andric 87753f127fSDimitry Andric _LIBCPP_END_NAMESPACE_STD 88753f127fSDimitry Andric 8906c3fb27SDimitry Andric #endif // _LIBCPP_STD_VER >= 20 90753f127fSDimitry Andric 91*b3edf446SDimitry Andric _LIBCPP_POP_MACROS 92*b3edf446SDimitry Andric 93753f127fSDimitry Andric #endif // _LIBCPP___ALGORITHM_RANGES_REPLACE_COPY_H 94