Skip to content

Commit d4ab164

Browse files
committed
[libcxx] applies changes regarding post-commit feedback to llvm#75259
Some of the feedback was also relevant to other files, and has been applied there too.
1 parent 5c37e71 commit d4ab164

File tree

10 files changed

+76
-13
lines changed

10 files changed

+76
-13
lines changed

libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/left_folds.pass.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ concept is_in_value_result =
5656
template <class Result, class T>
5757
concept is_dangling_with = std::same_as<Result, std::ranges::fold_left_with_iter_result<std::ranges::dangling, T>>;
5858

59-
struct Long {
59+
struct Integer {
6060
int value;
6161

62-
constexpr Long(int const x) : value(x) {}
62+
constexpr Integer(int const x) : value(x) {}
6363

64-
constexpr Long plus(int const x) const { return Long{value + x}; }
64+
constexpr Integer plus(int const x) const { return Integer{value + x}; }
6565

66-
friend constexpr bool operator==(Long const& x, Long const& y) = default;
66+
friend constexpr bool operator==(Integer const& x, Integer const& y) = default;
6767
};
6868

6969
template <std::ranges::input_range R, class T, class F, std::equality_comparable Expected>
@@ -74,6 +74,7 @@ constexpr void check_iterator(R& r, T const& init, F f, Expected const& expected
7474
assert(result.in == r.end());
7575
assert(result.value == expected);
7676
}
77+
7778
{
7879
auto telemetry = invocable_telemetry();
7980
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -89,6 +90,7 @@ constexpr void check_iterator(R& r, T const& init, F f, Expected const& expected
8990
std::same_as<Expected> decltype(auto) result = fold_left(r.begin(), r.end(), init, f);
9091
assert(result == expected);
9192
}
93+
9294
{
9395
auto telemetry = invocable_telemetry();
9496
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -108,6 +110,7 @@ constexpr void check_lvalue_range(R& r, T const& init, F f, Expected const& expe
108110
assert(result.in == r.end());
109111
assert(result.value == expected);
110112
}
113+
111114
{
112115
auto telemetry = invocable_telemetry();
113116
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -122,6 +125,7 @@ constexpr void check_lvalue_range(R& r, T const& init, F f, Expected const& expe
122125
std::same_as<Expected> decltype(auto) result = fold_left(r, init, f);
123126
assert(result == expected);
124127
}
128+
125129
{
126130
auto telemetry = invocable_telemetry();
127131
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -141,6 +145,7 @@ constexpr void check_rvalue_range(R& r, T const& init, F f, Expected const& expe
141145
is_dangling_with<Expected> decltype(auto) result = fold_left_with_iter(std::move(r2), init, f);
142146
assert(result.value == expected);
143147
}
148+
144149
{
145150
auto telemetry = invocable_telemetry();
146151
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -157,6 +162,7 @@ constexpr void check_rvalue_range(R& r, T const& init, F f, Expected const& expe
157162
std::same_as<Expected> decltype(auto) result = fold_left(std::move(r2), init, f);
158163
assert(result == expected);
159164
}
165+
160166
{
161167
auto telemetry = invocable_telemetry();
162168
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -183,7 +189,7 @@ constexpr void empty_range_test_case() {
183189
check(data, -100, std::multiplies(), -100);
184190

185191
check(data | std::views::take_while([](auto) { return false; }), 1.23, std::plus(), 1.23);
186-
check(data, Long(52), &Long::plus, Long(52));
192+
check(data, Integer(52), &Integer::plus, Integer(52));
187193
}
188194

189195
constexpr void common_range_test_case() {
@@ -206,7 +212,7 @@ constexpr void common_range_test_case() {
206212
};
207213
check(data, 0, fib, fibonacci(data.back()));
208214

209-
check(data, Long(0), &Long::plus, Long(triangular_sum(data)));
215+
check(data, Integer(0), &Integer::plus, Integer(triangular_sum(data)));
210216
}
211217

212218
constexpr void non_common_range_test_case() {
@@ -266,6 +272,7 @@ void runtime_only_test_case() {
266272
assert(result.in == data.end());
267273
assert(result.value == expected);
268274
}
275+
269276
{
270277
auto input = std::istringstream(raw_data);
271278
auto data = std::views::istream<std::string>(input);
@@ -274,11 +281,13 @@ void runtime_only_test_case() {
274281
assert(result.in == data.end());
275282
assert(result.value == expected);
276283
}
284+
277285
{
278286
auto input = std::istringstream(raw_data);
279287
auto data = std::views::istream<std::string>(input);
280288
assert(fold_left(data.begin(), data.end(), init, std::plus()) == expected);
281289
}
290+
282291
{
283292
auto input = std::istringstream(raw_data);
284293
auto data = std::views::istream<std::string>(input);

libcxx/test/std/algorithms/alg.nonmodifying/alg.fold/requirements.compile.pass.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,21 @@
1010

1111
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1212

13-
// Checks that `std::ranges::fold_left_with_iter`'s requirements reject parameters that don't meet
14-
// the overloads' constraints.
13+
// template<input_iterator I, sentinel_for<I> S, class T,
14+
// indirectly-binary-left-foldable<T, I> F>
15+
// constexpr see below ranges::fold_left_with_iter(I first, S last, T init, F f);
16+
//
17+
// template<input_range R, class T, indirectly-binary-left-foldable<T, iterator_t<R>> F>
18+
// constexpr see below ranges::fold_left_with_iter(R&& r, T init, F f);
19+
20+
// template<input_iterator I, sentinel_for<I> S, class T,
21+
// indirectly-binary-left-foldable<T, I> F>
22+
// constexpr see below ranges::fold_left(I first, S last, T init, F f);
23+
//
24+
// template<input_range R, class T, indirectly-binary-left-foldable<T, iterator_t<R>> F>
25+
// constexpr see below ranges::fold_left(R&& r, T init, F f);
26+
27+
// Checks that the algorithm requirements reject parameters that don't meet the overloads' constraints.
1528

1629
#include <algorithm>
1730
#include <concepts>

libcxx/test/std/algorithms/algorithms.results/in_found_result.pass.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct ConvertibleFrom {
6464
};
6565

6666
constexpr bool test() {
67+
// Checks that conversion operations are correct.
6768
{
6869
std::ranges::in_found_result<double> res{10, true};
6970
assert(res.in == 10);
@@ -72,6 +73,8 @@ constexpr bool test() {
7273
assert(res2.in.content == 10);
7374
assert(res2.found == true);
7475
}
76+
77+
// Checks that conversions are possible when one of the types is move-only.
7578
{
7679
std::ranges::in_found_result<MoveOnly> res{MoveOnly{}, false};
7780
assert(res.in.get() == 1);
@@ -82,10 +85,13 @@ constexpr bool test() {
8285
assert(res.in.get() == 0);
8386
assert(!res.found);
8487
}
85-
auto [in, found] = std::ranges::in_found_result<int>{2, false};
86-
assert(in == 2);
87-
assert(!found);
8888

89+
// Checks that structured bindings get the correct values.
90+
{
91+
auto [in, found] = std::ranges::in_found_result<int>{2, false};
92+
assert(in == 2);
93+
assert(!found);
94+
}
8995
return true;
9096
}
9197

libcxx/test/std/algorithms/algorithms.results/in_fun_result.pass.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static_assert(std::is_convertible_v<const std::ranges::in_fun_result<int, int>&&
4848
static_assert(std::is_move_constructible_v<std::ranges::in_fun_result<MoveOnly, int>>);
4949
static_assert(std::is_move_constructible_v<std::ranges::in_fun_result<int, MoveOnly>>);
5050

51-
// should not copy constructible with move-only type
51+
// should not be copy constructible with move-only type
5252
static_assert(!std::is_copy_constructible_v<std::ranges::in_fun_result<MoveOnly, int>>);
5353
static_assert(!std::is_copy_constructible_v<std::ranges::in_fun_result<int, MoveOnly>>);
5454

@@ -64,6 +64,7 @@ struct ConvertibleFrom {
6464
};
6565

6666
constexpr bool test() {
67+
// Checks that conversion operations are correct.
6768
{
6869
std::ranges::in_fun_result<int, double> res{10, 0.};
6970
assert(res.in == 10);
@@ -72,6 +73,8 @@ constexpr bool test() {
7273
assert(res2.in.content == 10);
7374
assert(res2.fun.content == 0.);
7475
}
76+
77+
// Checks that conversions are possible when one of the types is move-only.
7578
{
7679
std::ranges::in_fun_result<MoveOnly, int> res{MoveOnly{}, 2};
7780
assert(res.in.get() == 1);
@@ -81,6 +84,8 @@ constexpr bool test() {
8184
assert(res2.in.get() == 1);
8285
assert(res2.fun == 2);
8386
}
87+
88+
// Checks that structured bindings get the correct values.
8489
{
8590
auto [in, fun] = std::ranges::in_fun_result<int, int>{1, 2};
8691
assert(in == 1);

libcxx/test/std/algorithms/algorithms.results/in_in_out_result.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct ConvertibleFrom {
6767
};
6868

6969
constexpr bool test() {
70+
// Checks that conversion operations are correct.
7071
{
7172
std::ranges::in_in_out_result<int, double, float> res{10, 0., 1.f};
7273
assert(res.in1 == 10);
@@ -77,13 +78,17 @@ constexpr bool test() {
7778
assert(res2.in2.content == 0.);
7879
assert(res2.out.content == 1.f);
7980
}
81+
82+
// Checks that conversions are possible when one of the types is move-only.
8083
{
8184
std::ranges::in_in_out_result<MoveOnly, int, int> res1{MoveOnly{}, 0, 0};
8285
assert(res1.in1.get() == 1);
8386
auto res2 = static_cast<std::ranges::in_in_out_result<MoveOnly, int, int>>(std::move(res1));
8487
assert(res1.in1.get() == 0);
8588
assert(res2.in1.get() == 1);
8689
}
90+
91+
// Checks that structured bindings get the correct values.
8792
{
8893
auto [in1, in2, out] = std::ranges::in_in_out_result<int, int, int>{1, 2, 3};
8994
assert(in1 == 1);

libcxx/test/std/algorithms/algorithms.results/in_in_result.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct ConstructibleFrom {
5959
};
6060

6161
constexpr bool test() {
62+
// Checks that conversion operations are correct.
6263
{
6364
std::ranges::in_in_result<int, double> res{10L, 0.};
6465
assert(res.in1 == 10);
@@ -67,12 +68,16 @@ constexpr bool test() {
6768
assert(res2.in1.content == 10);
6869
assert(res2.in2.content == 0.);
6970
}
71+
72+
// Checks that conversions are possible when one of the types is move-only.
7073
{
7174
std::ranges::in_in_result<MoveOnly, int> res{MoveOnly{}, 0};
7275
assert(res.in1.get() == 1);
7376
[[maybe_unused]] auto res2 = static_cast<std::ranges::in_in_result<MoveOnly, int>>(std::move(res));
7477
assert(res.in1.get() == 0);
7578
}
79+
80+
// Checks that structured bindings get the correct values.
7681
{
7782
auto [in1, in2] = std::ranges::in_in_result<int, int>{1, 2};
7883
assert(in1 == 1);

libcxx/test/std/algorithms/algorithms.results/in_out_out_result.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ struct ConvertibleFrom {
6565
};
6666

6767
constexpr bool test() {
68+
// Checks that conversion operations are correct.
6869
{
6970
std::ranges::in_out_out_result<int, double, float> res{10, 0., 1.f};
7071
assert(res.in == 10);
@@ -75,13 +76,17 @@ constexpr bool test() {
7576
assert(res2.out1.content == 0.);
7677
assert(res2.out2.content == 1.f);
7778
}
79+
80+
// Checks that conversions are possible when one of the types is move-only.
7881
{
7982
std::ranges::in_out_out_result<MoveOnly, int, int> res1{MoveOnly{}, 0, 0};
8083
assert(res1.in.get() == 1);
8184
auto res2 = static_cast<std::ranges::in_out_out_result<MoveOnly, int, int>>(std::move(res1));
8285
assert(res1.in.get() == 0);
8386
assert(res2.in.get() == 1);
8487
}
88+
89+
// Checks that structured bindings get the correct values.
8590
{
8691
auto [in, out1, out2] = std::ranges::in_out_out_result<int, int, int>{1, 2, 3};
8792
assert(in == 1);

libcxx/test/std/algorithms/algorithms.results/in_out_result.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct ConvertibleFrom {
5959
};
6060

6161
constexpr bool test() {
62+
// Checks that conversion operations are correct.
6263
{
6364
std::ranges::in_out_result<double, int> res{10, 1};
6465
assert(res.in == 10);
@@ -67,6 +68,8 @@ constexpr bool test() {
6768
assert(res2.in.content == 10);
6869
assert(res2.out.content == 1);
6970
}
71+
72+
// Checks that conversions are possible when one of the types is move-only.
7073
{
7174
std::ranges::in_out_result<MoveOnly, int> res{MoveOnly{}, 10};
7275
assert(res.in.get() == 1);
@@ -77,6 +80,8 @@ constexpr bool test() {
7780
assert(res2.in.get() == 1);
7881
assert(res2.out == 10);
7982
}
83+
84+
// Checks that structured bindings get the correct values.
8085
{
8186
auto [min, max] = std::ranges::in_out_result<int, int>{1, 2};
8287
assert(min == 1);

libcxx/test/std/algorithms/algorithms.results/in_value_result.pass.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static_assert(
5353
static_assert(std::is_move_constructible_v<std::ranges::in_value_result<MoveOnly, int>>);
5454
static_assert(std::is_move_constructible_v<std::ranges::in_value_result<int, MoveOnly>>);
5555

56-
// should not copy constructible with move-only type
56+
// should not be copy constructible with move-only type
5757
static_assert(!std::is_copy_constructible_v<std::ranges::in_value_result<MoveOnly, int>>);
5858
static_assert(!std::is_copy_constructible_v<std::ranges::in_value_result<int, MoveOnly>>);
5959

@@ -71,6 +71,7 @@ struct ConvertibleFrom {
7171
};
7272

7373
constexpr bool test() {
74+
// Checks that conversion operations are correct.
7475
{
7576
std::ranges::in_value_result<int, double> res{10, 0.};
7677
assert(res.in == 10);
@@ -79,6 +80,8 @@ constexpr bool test() {
7980
assert(res2.in.content == 10);
8081
assert(res2.value.content == 0.);
8182
}
83+
84+
// Checks that conversions are possible when one of the types is move-only.
8285
{
8386
std::ranges::in_value_result<MoveOnly, int> res{MoveOnly{}, 2};
8487
assert(res.in.get() == 1);
@@ -88,6 +91,8 @@ constexpr bool test() {
8891
assert(res2.in.get() == 1);
8992
assert(res2.value == 2);
9093
}
94+
95+
// Checks that structured bindings get the correct values.
9196
{
9297
auto [in, value] = std::ranges::in_value_result<int, int>{1, 2};
9398
assert(in == 1);

libcxx/test/std/algorithms/algorithms.results/min_max_result.pass.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct ConvertibleFrom {
6060
};
6161

6262
constexpr bool test() {
63+
// Checks that conversion operations are correct.
6364
{
6465
std::ranges::min_max_result<double> res{10, 1};
6566
assert(res.min == 10);
@@ -68,6 +69,8 @@ constexpr bool test() {
6869
assert(res2.min.content == 10);
6970
assert(res2.max.content == 1);
7071
}
72+
73+
// Checks that conversions are possible when one of the types is move-only.
7174
{
7275
std::ranges::min_max_result<MoveOnly> res{MoveOnly{}, MoveOnly{}};
7376
assert(res.min.get() == 1);
@@ -78,6 +81,8 @@ constexpr bool test() {
7881
assert(res2.min.get() == 1);
7982
assert(res2.max.get() == 1);
8083
}
84+
85+
// Checks that structured bindings get the correct values.
8186
{
8287
auto [min, max] = std::ranges::min_max_result<int>{1, 2};
8388
assert(min == 1);

0 commit comments

Comments
 (0)