|
13 | 13 | #include <__algorithm/for_each_segment.h>
|
14 | 14 | #include <__config>
|
15 | 15 | #include <__iterator/segmented_iterator.h>
|
16 |
| -#include <__ranges/movable_box.h> |
17 |
| -#include <__utility/in_place.h> |
18 |
| -#include <__utility/move.h> |
| 16 | +#include <__type_traits/enable_if.h> |
19 | 17 |
|
20 | 18 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
|
21 | 19 | # pragma GCC system_header
|
22 | 20 | #endif
|
23 | 21 |
|
24 |
| -_LIBCPP_PUSH_MACROS |
25 |
| -#include <__undef_macros> |
26 |
| - |
27 | 22 | _LIBCPP_BEGIN_NAMESPACE_STD
|
28 | 23 |
|
29 |
| -template <class _InputIterator, class _Function> |
30 |
| -_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function |
31 |
| -for_each(_InputIterator __first, _InputIterator __last, _Function __f) { |
| 24 | +template <class _InputIterator, class _Sent, class _Func> |
| 25 | +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __for_each(_InputIterator __first, _Sent __last, _Func& __f) { |
32 | 26 | for (; __first != __last; ++__first)
|
33 | 27 | __f(*__first);
|
34 |
| - return __f; |
35 | 28 | }
|
36 | 29 |
|
37 |
| -// __movable_box is available in C++20, but is actually a copyable-box, so optimization is only correct in C++23 |
38 |
| -#if _LIBCPP_STD_VER >= 23 |
39 |
| -template <class _SegmentedIterator, class _Function> |
40 |
| - requires __is_segmented_iterator<_SegmentedIterator>::value |
41 |
| -_LIBCPP_HIDE_FROM_ABI constexpr _Function |
42 |
| -for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Function __func) { |
43 |
| - ranges::__movable_box<_Function> __wrapped_func(in_place, std::move(__func)); |
44 |
| - std::__for_each_segment(__first, __last, [&](auto __lfirst, auto __llast) { |
45 |
| - __wrapped_func = |
46 |
| - ranges::__movable_box<_Function>(in_place, std::for_each(__lfirst, __llast, std::move(*__wrapped_func))); |
| 30 | +#ifndef _LIBCPP_CXX03_LANG |
| 31 | +template <class _SegmentedIterator, |
| 32 | + class _Function, |
| 33 | + __enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0> |
| 34 | +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void |
| 35 | +__for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Function& __func) { |
| 36 | + using __local_iterator_t = typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator; |
| 37 | + std::__for_each_segment(__first, __last, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) { |
| 38 | + std::__for_each(__lfirst, __llast, __func); |
47 | 39 | });
|
48 |
| - return std::move(*__wrapped_func); |
49 | 40 | }
|
50 |
| -#endif // _LIBCPP_STD_VER >= 23 |
| 41 | +#endif // !_LIBCPP_CXX03_LANG |
51 | 42 |
|
52 |
| -_LIBCPP_END_NAMESPACE_STD |
| 43 | +template <class _InputIterator, class _Function> |
| 44 | +_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function |
| 45 | +for_each(_InputIterator __first, _InputIterator __last, _Function __f) { |
| 46 | + std::__for_each(__first, __last, __f); |
| 47 | + return __f; |
| 48 | +} |
53 | 49 |
|
54 |
| -_LIBCPP_POP_MACROS |
| 50 | +_LIBCPP_END_NAMESPACE_STD |
55 | 51 |
|
56 | 52 | #endif // _LIBCPP___ALGORITHM_FOR_EACH_H
|
0 commit comments