21
21
# pragma GCC system_header
22
22
#endif
23
23
24
- _LIBCPP_PUSH_MACROS
25
- #include < __undef_macros>
26
-
27
24
_LIBCPP_BEGIN_NAMESPACE_STD
28
25
29
26
template <class _InputIterator , class _Sent , class _Func >
@@ -32,29 +29,19 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __for_each(_InputIterat
32
29
__f (*__first);
33
30
}
34
31
35
- // __segment_processor handles the per-segment processing by applying the function object __func_ to each
36
- // element within the segment.
37
- template <class _Func >
38
- struct __segment_processor {
39
- _Func& __func_;
40
-
41
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __segment_processor (_Func& __f) : __func_(__f) {}
42
-
43
- template <class _SegmentedIterator >
44
- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
45
- operator ()(typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator __lfirst,
46
- typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator __llast) {
47
- std::__for_each (__lfirst, __llast, __func_);
48
- }
49
- };
50
-
32
+ #ifndef _LIBCPP_CXX03_LANG
51
33
template <class _SegmentedIterator ,
52
34
class _Function ,
53
35
__enable_if_t <__is_segmented_iterator<_SegmentedIterator>::value, int > = 0 >
54
36
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
55
37
__for_each (_SegmentedIterator __first, _SegmentedIterator __last, _Function& __func) {
56
- std::__for_each_segment (__first, __last, std::__segment_processor<_Function>(__func));
38
+ using _Traits = __segmented_iterator_traits<_SegmentedIterator>;
39
+ std::__for_each_segment (
40
+ __first, __last, [&](typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
41
+ std::__for_each (__lfirst, __llast, __func);
42
+ });
57
43
}
44
+ #endif
58
45
59
46
template <class _InputIterator , class _Function >
60
47
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function
@@ -65,6 +52,4 @@ for_each(_InputIterator __first, _InputIterator __last, _Function __f) {
65
52
66
53
_LIBCPP_END_NAMESPACE_STD
67
54
68
- _LIBCPP_POP_MACROS
69
-
70
55
#endif // _LIBCPP___ALGORITHM_FOR_EACH_H
0 commit comments