Skip to content

Commit f0ea888

Browse files
authored
[libcxx] applies changes regarding post-commit feedback to #75259 (#76534)
Some of the feedback was also relevant to other files, and has been applied there too.
1 parent b865960 commit f0ea888

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
@@ -59,14 +59,14 @@ concept is_in_value_result =
5959
template <class Result, class T>
6060
concept is_dangling_with = std::same_as<Result, std::ranges::fold_left_with_iter_result<std::ranges::dangling, T>>;
6161

62-
struct Long {
62+
struct Integer {
6363
int value;
6464

65-
constexpr Long(int const x) : value(x) {}
65+
constexpr Integer(int const x) : value(x) {}
6666

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

69-
friend constexpr bool operator==(Long const& x, Long const& y) = default;
69+
friend constexpr bool operator==(Integer const& x, Integer const& y) = default;
7070
};
7171

7272
template <std::ranges::input_range R, class T, class F, std::equality_comparable Expected>
@@ -77,6 +77,7 @@ constexpr void check_iterator(R& r, T const& init, F f, Expected const& expected
7777
assert(result.in == r.end());
7878
assert(result.value == expected);
7979
}
80+
8081
{
8182
auto telemetry = invocable_telemetry();
8283
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -92,6 +93,7 @@ constexpr void check_iterator(R& r, T const& init, F f, Expected const& expected
9293
std::same_as<Expected> decltype(auto) result = fold_left(r.begin(), r.end(), init, f);
9394
assert(result == expected);
9495
}
96+
9597
{
9698
auto telemetry = invocable_telemetry();
9799
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -111,6 +113,7 @@ constexpr void check_lvalue_range(R& r, T const& init, F f, Expected const& expe
111113
assert(result.in == r.end());
112114
assert(result.value == expected);
113115
}
116+
114117
{
115118
auto telemetry = invocable_telemetry();
116119
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -125,6 +128,7 @@ constexpr void check_lvalue_range(R& r, T const& init, F f, Expected const& expe
125128
std::same_as<Expected> decltype(auto) result = fold_left(r, init, f);
126129
assert(result == expected);
127130
}
131+
128132
{
129133
auto telemetry = invocable_telemetry();
130134
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -144,6 +148,7 @@ constexpr void check_rvalue_range(R& r, T const& init, F f, Expected const& expe
144148
is_dangling_with<Expected> decltype(auto) result = fold_left_with_iter(std::move(r2), init, f);
145149
assert(result.value == expected);
146150
}
151+
147152
{
148153
auto telemetry = invocable_telemetry();
149154
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -160,6 +165,7 @@ constexpr void check_rvalue_range(R& r, T const& init, F f, Expected const& expe
160165
std::same_as<Expected> decltype(auto) result = fold_left(std::move(r2), init, f);
161166
assert(result == expected);
162167
}
168+
163169
{
164170
auto telemetry = invocable_telemetry();
165171
auto f2 = invocable_with_telemetry(f, telemetry);
@@ -186,7 +192,7 @@ constexpr void empty_range_test_case() {
186192
check(data, -100, std::multiplies(), -100);
187193

188194
check(data | std::views::take_while([](auto) { return false; }), 1.23, std::plus(), 1.23);
189-
check(data, Long(52), &Long::plus, Long(52));
195+
check(data, Integer(52), &Integer::plus, Integer(52));
190196
}
191197

192198
constexpr void common_range_test_case() {
@@ -209,7 +215,7 @@ constexpr void common_range_test_case() {
209215
};
210216
check(data, 0, fib, fibonacci(data.back()));
211217

212-
check(data, Long(0), &Long::plus, Long(triangular_sum(data)));
218+
check(data, Integer(0), &Integer::plus, Integer(triangular_sum(data)));
213219
}
214220

215221
constexpr void non_common_range_test_case() {
@@ -269,6 +275,7 @@ void runtime_only_test_case() {
269275
assert(result.in == data.end());
270276
assert(result.value == expected);
271277
}
278+
272279
{
273280
auto input = std::istringstream(raw_data);
274281
auto data = std::views::istream<std::string>(input);
@@ -277,11 +284,13 @@ void runtime_only_test_case() {
277284
assert(result.in == data.end());
278285
assert(result.value == expected);
279286
}
287+
280288
{
281289
auto input = std::istringstream(raw_data);
282290
auto data = std::views::istream<std::string>(input);
283291
assert(fold_left(data.begin(), data.end(), init, std::plus()) == expected);
284292
}
293+
285294
{
286295
auto input = std::istringstream(raw_data);
287296
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)