Skip to content

Commit 90c826b

Browse files
committed
Address ldionne's review comments
1 parent a5148ec commit 90c826b

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

libcxx/include/__algorithm/for_each.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define _LIBCPP___ALGORITHM_FOR_EACH_H
1212

1313
#include <__algorithm/for_each_segment.h>
14+
#include <__algorithm/iterator_operations.h>
1415
#include <__config>
1516
#include <__iterator/segmented_iterator.h>
1617
#include <__type_traits/enable_if.h>

libcxx/include/__algorithm/ranges_for_each.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <__algorithm/for_each.h>
1313
#include <__algorithm/in_fun_result.h>
14+
#include <__algorithm/iterator_operations.h>
1415
#include <__config>
1516
#include <__functional/identity.h>
1617
#include <__functional/invoke.h>
@@ -45,7 +46,8 @@ struct __for_each {
4546
if constexpr (random_access_iterator<_Iter> && sized_sentinel_for<_Sent, _Iter>) {
4647
auto __n = __last - __first;
4748
auto __end = __first + __n;
48-
std::for_each(__first, __end, [&](auto&& __val) { std::invoke(__func, std::invoke(__proj, __val)); });
49+
auto __f = [&](auto&& __val) { std::invoke(__func, std::invoke(__proj, __val)); };
50+
std::__for_each<_RangeAlgPolicy>(__first, __end, __f);
4951
return {std::move(__end), std::move(__func)};
5052
} else {
5153
for (; __first != __last; ++__first)

libcxx/include/__algorithm/ranges_for_each_n.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include <__algorithm/for_each.h>
1313
#include <__algorithm/in_fun_result.h>
14+
#include <__algorithm/iterator_operations.h>
1415
#include <__config>
1516
#include <__functional/identity.h>
1617
#include <__functional/invoke.h>
@@ -43,7 +44,8 @@ struct __for_each_n {
4344
operator()(_Iter __first, iter_difference_t<_Iter> __count, _Func __func, _Proj __proj = {}) const {
4445
if constexpr (random_access_iterator<_Iter>) {
4546
auto __last = __first + __count;
46-
std::for_each(__first, __last, [&](auto&& __val) { std::invoke(__func, std::invoke(__proj, __val)); });
47+
auto __f = [&](auto&& __val) { std::invoke(__func, std::invoke(__proj, __val)); };
48+
std::__for_each<_RangeAlgPolicy>(__first, __last, __f);
4749
return {std::move(__last), std::move(__func)};
4850
} else {
4951
while (__count-- > 0) {

libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ struct deque_test {
127127

128128
/*TEST_CONSTEXPR_CXX23*/
129129
void test_segmented_deque_iterator() { // TODO: Mark as TEST_CONSTEXPR_CXX23 once std::deque is constexpr
130-
// check that segmented iterators work properly
130+
// check that segmented deque iterators work properly
131131
int sizes[] = {0, 1, 2, 1023, 1024, 1025, 2047, 2048, 2049};
132132
for (const int size : sizes) {
133133
std::deque<int> d(size);

libcxx/test/std/algorithms/alg.nonmodifying/alg.foreach/ranges.for_each_n.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct deque_test {
8383

8484
/*TEST_CONSTEXPR_CXX23*/
8585
void test_segmented_deque_iterator() { // TODO: Mark as TEST_CONSTEXPR_CXX23 once std::deque is constexpr
86-
// check that segmented iterators work properly
86+
// check that segmented deque iterators work properly
8787
int sizes[] = {0, 1, 2, 1023, 1024, 1025, 2047, 2048, 2049};
8888
for (const int size : sizes) {
8989
std::deque<int> d(size);

0 commit comments

Comments
 (0)