Skip to content

Commit f314697

Browse files
committed
Inline tests and remove std::ref
1 parent 7b1dbd3 commit f314697

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,40 @@ TEST_CONSTEXPR_CXX20 bool test() {
6464
const unsigned s = sizeof(ia) / sizeof(ia[0]);
6565

6666
{
67-
auto f = for_each_test(0);
68-
Iter it = std::for_each_n(Iter(ia), 0, std::ref(f));
67+
unsigned count = 0;
68+
Iter it = std::for_each_n(Iter(ia), 0, [&count](int& i) mutable {
69+
++i;
70+
++count;
71+
});
6972
assert(it == Iter(ia));
70-
assert(f.count == 0);
73+
assert(count == 0);
7174
}
7275

7376
{
74-
auto f = for_each_test(0);
75-
Iter it = std::for_each_n(Iter(ia), s, std::ref(f));
76-
77+
unsigned count = 0;
78+
Iter it = std::for_each_n(Iter(ia), s, [&count](int& i) mutable {
79+
++i;
80+
++count;
81+
});
7782
assert(it == Iter(ia + s));
78-
assert(f.count == s);
83+
assert(count == s);
7984
for (unsigned i = 0; i < s; ++i)
8085
assert(ia[i] == static_cast<int>(i + 1));
8186
}
8287

8388
{
84-
auto f = for_each_test(0);
85-
Iter it = std::for_each_n(Iter(ia), 1, std::ref(f));
86-
89+
unsigned count = 0;
90+
Iter it = std::for_each_n(Iter(ia), 1, [&count](int& i) mutable {
91+
++i;
92+
++count;
93+
});
8794
assert(it == Iter(ia + 1));
88-
assert(f.count == 1);
95+
assert(count == 1);
8996
for (unsigned i = 0; i < 1; ++i)
9097
assert(ia[i] == static_cast<int>(i + 2));
9198
}
9299
}
93100

94-
#if TEST_STD_VER > 11
95101
{
96102
int ia[] = {1, 3, 6, 7};
97103
int expected[] = {3, 5, 8, 9};
@@ -100,7 +106,6 @@ TEST_CONSTEXPR_CXX20 bool test() {
100106
auto it = std::for_each_n(std::begin(ia), N, [](int& a) { a += 2; });
101107
assert(it == (std::begin(ia) + N) && std::equal(std::begin(ia), std::end(ia), std::begin(expected)));
102108
}
103-
#endif
104109

105110
if (!TEST_IS_CONSTANT_EVALUATED) // TODO: Use TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED when std::deque is made constexpr
106111
test_segmented_deque_iterator();

0 commit comments

Comments
 (0)