99#ifndef _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
1010#define _LIBCPP___ALGORITHM_RANGES_COPY_IF_H
1111
12+ #include < __algorithm/copy_if.h>
1213#include < __algorithm/in_out_result.h>
1314#include < __config>
1415#include < __functional/identity.h>
@@ -37,18 +38,6 @@ template <class _Ip, class _Op>
3738using copy_if_result = in_out_result<_Ip, _Op>;
3839
3940struct __copy_if {
40- template <class _InIter , class _Sent , class _OutIter , class _Proj , class _Pred >
41- _LIBCPP_HIDE_FROM_ABI static constexpr copy_if_result<_InIter, _OutIter>
42- __copy_if_impl (_InIter __first, _Sent __last, _OutIter __result, _Pred& __pred, _Proj& __proj) {
43- for (; __first != __last; ++__first) {
44- if (std::invoke (__pred, std::invoke (__proj, *__first))) {
45- *__result = *__first;
46- ++__result;
47- }
48- }
49- return {std::move (__first), std::move (__result)};
50- }
51-
5241 template <input_iterator _Iter,
5342 sentinel_for<_Iter> _Sent,
5443 weakly_incrementable _OutIter,
@@ -57,7 +46,8 @@ struct __copy_if {
5746 requires indirectly_copyable<_Iter, _OutIter>
5847 _LIBCPP_HIDE_FROM_ABI constexpr copy_if_result<_Iter, _OutIter>
5948 operator ()(_Iter __first, _Sent __last, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
60- return __copy_if_impl (std::move (__first), std::move (__last), std::move (__result), __pred, __proj);
49+ auto __res = std::__copy_if (std::move (__first), std::move (__last), std::move (__result), __pred, __proj);
50+ return {std::move (__res.first ), std::move (__res.second )};
6151 }
6252
6353 template <input_range _Range,
@@ -67,7 +57,8 @@ struct __copy_if {
6757 requires indirectly_copyable<iterator_t <_Range>, _OutIter>
6858 _LIBCPP_HIDE_FROM_ABI constexpr copy_if_result<borrowed_iterator_t <_Range>, _OutIter>
6959 operator ()(_Range&& __r, _OutIter __result, _Pred __pred, _Proj __proj = {}) const {
70- return __copy_if_impl (ranges::begin (__r), ranges::end (__r), std::move (__result), __pred, __proj);
60+ auto __res = std::__copy_if (ranges::begin (__r), ranges::end (__r), std::move (__result), __pred, __proj);
61+ return {std::move (__res.first ), std::move (__res.second )};
7162 }
7263};
7364
0 commit comments