Skip to content

Commit a33aee8

Browse files
committed
Fix reviewer comments
1 parent 6bb2d23 commit a33aee8

File tree

15 files changed

+41
-12
lines changed

15 files changed

+41
-12
lines changed

libcxx/include/__algorithm/for_each.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,26 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void __for_each(_InputIterat
3434

3535
// __segment_processor handles the per-segment processing by applying the function object __func_ to each
3636
// element within the segment.
37-
template <class _SegmentedIterator, class _Func>
37+
template <class _Func>
3838
struct __segment_processor {
39-
using _Traits _LIBCPP_NODEBUG = __segmented_iterator_traits<_SegmentedIterator>;
40-
4139
_Func& __func_;
4240

4341
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR explicit __segment_processor(_Func& __f) : __func_(__f) {}
4442

43+
template <class _SegmentedIterator>
4544
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
46-
operator()(typename _Traits::__local_iterator __lfirst, typename _Traits::__local_iterator __llast) {
45+
operator()(typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator __lfirst,
46+
typename __segmented_iterator_traits<_SegmentedIterator>::__local_iterator __llast) {
4747
std::__for_each(__lfirst, __llast, __func_);
4848
}
4949
};
5050

5151
template <class _SegmentedIterator,
5252
class _Function,
5353
__enable_if_t<__is_segmented_iterator<_SegmentedIterator>::value, int> = 0>
54-
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Function
55-
__for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Function __func) {
56-
std::__for_each_segment(__first, __last, std::__segment_processor<_SegmentedIterator, _Function>(__func));
57-
return __func;
54+
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 void
55+
__for_each(_SegmentedIterator __first, _SegmentedIterator __last, _Function& __func) {
56+
std::__for_each_segment(__first, __last, std::__segment_processor<_Function>(__func));
5857
}
5958

6059
template <class _InputIterator, class _Function>

libcxx/include/__algorithm/for_each_segment.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ __for_each_segment(_SegmentedIterator __first, _SegmentedIterator __last, _Funct
3232

3333
// We are in a single segment, so we might not be at the beginning or end
3434
if (__sfirst == __slast) {
35-
__func(_Traits::__local(__first), _Traits::__local(__last));
35+
__func.template operator()<_SegmentedIterator>(_Traits::__local(__first), _Traits::__local(__last));
3636
return;
3737
}
3838

3939
// We have more than one segment. Iterate over the first segment, since we might not start at the beginning
40-
__func(_Traits::__local(__first), _Traits::__end(__sfirst));
40+
__func.template operator()<_SegmentedIterator>(_Traits::__local(__first), _Traits::__end(__sfirst));
4141
++__sfirst;
4242
// iterate over the segments which are guaranteed to be completely in the range
4343
while (__sfirst != __slast) {
44-
__func(_Traits::__begin(__sfirst), _Traits::__end(__sfirst));
44+
__func.template operator()<_SegmentedIterator>(_Traits::__begin(__sfirst), _Traits::__end(__sfirst));
4545
++__sfirst;
4646
}
4747
// iterate over the last segment
48-
__func(_Traits::__begin(__sfirst), _Traits::__local(__last));
48+
__func.template operator()<_SegmentedIterator>(_Traits::__begin(__sfirst), _Traits::__local(__last));
4949
}
5050

5151
_LIBCPP_END_NAMESPACE_STD

libcxx/include/algorithm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@ template <class BidirectionalIterator, class Compare>
20612061
# include <cstring>
20622062
# include <iterator>
20632063
# include <memory>
2064+
# include <optional>
20642065
# include <stdexcept>
20652066
# include <type_traits>
20662067
# include <utility>

libcxx/include/array

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ _LIBCPP_POP_MACROS
566566
# include <cstdlib>
567567
# include <iterator>
568568
# include <new>
569+
# include <optional>
569570
# include <type_traits>
570571
# include <utility>
571572
# endif

libcxx/include/bitset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ _LIBCPP_POP_MACROS
973973
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
974974
# include <concepts>
975975
# include <cstdlib>
976+
# include <optional>
976977
# include <type_traits>
977978
# endif
978979
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)

libcxx/include/codecvt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ _LIBCPP_END_NAMESPACE_STD
596596
# include <limits>
597597
# include <mutex>
598598
# include <new>
599+
# include <optional>
599600
# include <stdexcept>
600601
# include <type_traits>
601602
# include <typeinfo>

libcxx/include/condition_variable

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ _LIBCPP_POP_MACROS
357357
# include <initializer_list>
358358
# include <iosfwd>
359359
# include <new>
360+
# include <optional>
360361
# include <stdexcept>
361362
# include <system_error>
362363
# include <type_traits>

libcxx/include/ios

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,7 @@ _LIBCPP_POP_MACROS
887887
# include <limits>
888888
# include <mutex>
889889
# include <new>
890+
# include <optional>
890891
# include <stdexcept>
891892
# include <system_error>
892893
# include <type_traits>

libcxx/include/locale

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,6 +3666,7 @@ _LIBCPP_POP_MACROS
36663666
# include <cstdarg>
36673667
# include <iterator>
36683668
# include <mutex>
3669+
# include <optional>
36693670
# include <stdexcept>
36703671
# include <type_traits>
36713672
# include <typeinfo>

libcxx/include/streambuf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ _LIBCPP_POP_MACROS
386386

387387
# if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
388388
# include <cstdint>
389+
# include <optional>
389390
# endif
390391
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
391392

libcxx/include/string

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4027,6 +4027,7 @@ _LIBCPP_POP_MACROS
40274027
# include <cstdlib>
40284028
# include <iterator>
40294029
# include <new>
4030+
# include <optional>
40304031
# include <type_traits>
40314032
# include <typeinfo>
40324033
# include <utility>

libcxx/include/string_view

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ _LIBCPP_POP_MACROS
952952
# include <concepts>
953953
# include <cstdlib>
954954
# include <iterator>
955+
# include <optional>
955956
# include <type_traits>
956957
# endif
957958
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)

libcxx/include/system_error

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ template <> struct hash<std::error_condition>;
168168
# include <cstdint>
169169
# include <cstring>
170170
# include <limits>
171+
# include <optional>
171172
# include <type_traits>
172173
# endif
173174
#endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)

libcxx/include/vector

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ template<class T, class charT> requires is-vector-bool-reference<T> // Since C++
362362
# if _LIBCPP_HAS_LOCALIZATION
363363
# include <locale>
364364
# endif
365+
# include <optional>
365366
# include <string>
366367
# include <string_view>
367368
# include <tuple>

libcxx/test/libcxx/algorithms/robust_against_copying_comparators.pass.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
#include <cassert>
1313
#include <compare>
1414
#include <cstddef>
15+
#include <deque>
16+
#include <ranges>
1517
#include <type_traits>
18+
#include <vector>
1619

1720
#include "test_macros.h"
1821

@@ -207,10 +210,25 @@ TEST_CONSTEXPR_CXX20 bool all_the_algorithms()
207210
return true;
208211
}
209212

213+
bool test_segmented_iterator() {
214+
int copies = 0;
215+
std::deque<int> dq(10);
216+
(void)std::for_each(dq.begin(), dq.end(), UnaryVoid<int>(&copies)); assert(copies == 1); copies = 0;
217+
218+
#if TEST_STD_VER >= 20
219+
std::vector<std::vector<int>> vecs(3, std::vector<int>(10));
220+
auto v = std::views::join(vecs);
221+
std::for_each(v.begin(), v.end(), UnaryVoid<int>(&copies)); assert(copies == 1); copies = 0;
222+
#endif
223+
224+
return true;
225+
}
226+
210227
int main(int, char**)
211228
{
212229
all_the_algorithms<void*>();
213230
all_the_algorithms<int>();
231+
test_segmented_iterator();
214232
#if TEST_STD_VER > 17
215233
static_assert(all_the_algorithms<void*>());
216234
static_assert(all_the_algorithms<int>());

0 commit comments

Comments
 (0)