Skip to content

Commit 5a225dd

Browse files
committed
Refactor to simplify logic of for_each_n_segment.h
1 parent 8db6dd0 commit 5a225dd

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

libcxx/include/__algorithm/for_each.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
#include <__iterator/segmented_iterator.h>
1717
#include <__type_traits/enable_if.h>
1818
#include <__type_traits/invoke.h>
19+
#include <__utility/move.h>
1920

2021
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2122
# pragma GCC system_header
2223
#endif
2324

25+
_LIBCPP_PUSH_MACROS
26+
#include <__undef_macros>
27+
2428
_LIBCPP_BEGIN_NAMESPACE_STD
2529

2630
template <class _InputIterator, class _Sent, class _Func, class _Proj>
@@ -36,12 +40,13 @@ template <class _SegmentedIterator,
3640
class _Func,
3741
class _Proj,
3842
__enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0>
39-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
40-
__for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Function& __func, _Proj& __proj) {
43+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _SegmentedIterator
44+
__for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Func& __func, _Proj& __proj) {
4145
using __local_iterator_t = typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator;
4246
std::__for_each_segment(__first, __last, [&](__local_iterator_t __lfirst, __local_iterator_t __llast) {
4347
std::__for_each(__lfirst, __llast, __func, __proj);
4448
});
49+
return __last;
4550
}
4651
#endif // !_LIBCPP_CXX03_LANG
4752

@@ -55,4 +60,6 @@ for_each(_InputIterator __first, _InputIterator __last, _Func __f) {
5560

5661
_LIBCPP_END_NAMESPACE_STD
5762

63+
_LIBCPP_POP_MACROS
64+
5865
#endif // _LIBCPP___ALGORITHM_FOR_EACH_H

libcxx/include/__algorithm/for_each_n.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <__config>
1616
#include <__functional/identity.h>
1717
#include <__iterator/iterator_traits.h>
18-
#include <__iterator/next.h>
1918
#include <__iterator/segmented_iterator.h>
2019
#include <__type_traits/disjunction.h>
2120
#include <__type_traits/enable_if.h>
@@ -59,11 +58,11 @@ template <class _RandIter,
5958
class _Proj,
6059
__enable_if_t<__has_random_access_iterator_category<_RandIter>::value, int> = 0>
6160
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _RandIter
62-
__for_each_n(_RandIter __first, _Size __orig_n, _Func& __f) {
61+
__for_each_n(_RandIter __first, _Size __orig_n, _Func& __f, _Proj& __proj) {
6362
typename std::iterator_traits<_RandIter>::difference_type __n = __orig_n;
6463
auto __last = __first + __n;
6564
std::__for_each(__first, __last, __f, __proj);
66-
return std::move(__last);
65+
return __last;
6766
}
6867

6968
#ifndef _LIBCPP_CXX03_LANG

libcxx/include/__algorithm/for_each_n_segment.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,7 @@
1010
#define _LIBCPP___ALGORITHM_FOR_EACH_N_SEGMENT_H
1111

1212
#include <__config>
13-
<<<<<<< HEAD
1413
#include <__iterator/iterator_traits.h>
15-
=======
16-
#include <__iterator/distance.h>
17-
#include <__iterator/iterator_traits.h>
18-
#include <__iterator/next.h>
19-
>>>>>>> 4a86118918e8 (Fix review comments)
2014
#include <__iterator/segmented_iterator.h>
2115

2216
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)

0 commit comments

Comments
 (0)