Skip to content

[libcxx] applies changes regarding post-commit feedback to #75259 #76534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ concept is_in_value_result =
template <class Result, class T>
concept is_dangling_with = std::same_as<Result, std::ranges::fold_left_with_iter_result<std::ranges::dangling, T>>;

struct Long {
struct Integer {
int value;

constexpr Long(int const x) : value(x) {}
constexpr Integer(int const x) : value(x) {}

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

friend constexpr bool operator==(Long const& x, Long const& y) = default;
friend constexpr bool operator==(Integer const& x, Integer const& y) = default;
};

template <std::ranges::input_range R, class T, class F, std::equality_comparable Expected>
Expand All @@ -77,6 +77,7 @@ constexpr void check_iterator(R& r, T const& init, F f, Expected const& expected
assert(result.in == r.end());
assert(result.value == expected);
}

{
auto telemetry = invocable_telemetry();
auto f2 = invocable_with_telemetry(f, telemetry);
Expand All @@ -92,6 +93,7 @@ constexpr void check_iterator(R& r, T const& init, F f, Expected const& expected
std::same_as<Expected> decltype(auto) result = fold_left(r.begin(), r.end(), init, f);
assert(result == expected);
}

{
auto telemetry = invocable_telemetry();
auto f2 = invocable_with_telemetry(f, telemetry);
Expand All @@ -111,6 +113,7 @@ constexpr void check_lvalue_range(R& r, T const& init, F f, Expected const& expe
assert(result.in == r.end());
assert(result.value == expected);
}

{
auto telemetry = invocable_telemetry();
auto f2 = invocable_with_telemetry(f, telemetry);
Expand All @@ -125,6 +128,7 @@ constexpr void check_lvalue_range(R& r, T const& init, F f, Expected const& expe
std::same_as<Expected> decltype(auto) result = fold_left(r, init, f);
assert(result == expected);
}

{
auto telemetry = invocable_telemetry();
auto f2 = invocable_with_telemetry(f, telemetry);
Expand All @@ -144,6 +148,7 @@ constexpr void check_rvalue_range(R& r, T const& init, F f, Expected const& expe
is_dangling_with<Expected> decltype(auto) result = fold_left_with_iter(std::move(r2), init, f);
assert(result.value == expected);
}

{
auto telemetry = invocable_telemetry();
auto f2 = invocable_with_telemetry(f, telemetry);
Expand All @@ -160,6 +165,7 @@ constexpr void check_rvalue_range(R& r, T const& init, F f, Expected const& expe
std::same_as<Expected> decltype(auto) result = fold_left(std::move(r2), init, f);
assert(result == expected);
}

{
auto telemetry = invocable_telemetry();
auto f2 = invocable_with_telemetry(f, telemetry);
Expand All @@ -186,7 +192,7 @@ constexpr void empty_range_test_case() {
check(data, -100, std::multiplies(), -100);

check(data | std::views::take_while([](auto) { return false; }), 1.23, std::plus(), 1.23);
check(data, Long(52), &Long::plus, Long(52));
check(data, Integer(52), &Integer::plus, Integer(52));
}

constexpr void common_range_test_case() {
Expand All @@ -209,7 +215,7 @@ constexpr void common_range_test_case() {
};
check(data, 0, fib, fibonacci(data.back()));

check(data, Long(0), &Long::plus, Long(triangular_sum(data)));
check(data, Integer(0), &Integer::plus, Integer(triangular_sum(data)));
}

constexpr void non_common_range_test_case() {
Expand Down Expand Up @@ -269,6 +275,7 @@ void runtime_only_test_case() {
assert(result.in == data.end());
assert(result.value == expected);
}

{
auto input = std::istringstream(raw_data);
auto data = std::views::istream<std::string>(input);
Expand All @@ -277,11 +284,13 @@ void runtime_only_test_case() {
assert(result.in == data.end());
assert(result.value == expected);
}

{
auto input = std::istringstream(raw_data);
auto data = std::views::istream<std::string>(input);
assert(fold_left(data.begin(), data.end(), init, std::plus()) == expected);
}

{
auto input = std::istringstream(raw_data);
auto data = std::views::istream<std::string>(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@

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

// Checks that `std::ranges::fold_left_with_iter`'s requirements reject parameters that don't meet
// the overloads' constraints.
// template<input_iterator I, sentinel_for<I> S, class T,
// indirectly-binary-left-foldable<T, I> F>
// constexpr see below ranges::fold_left_with_iter(I first, S last, T init, F f);
//
// template<input_range R, class T, indirectly-binary-left-foldable<T, iterator_t<R>> F>
// constexpr see below ranges::fold_left_with_iter(R&& r, T init, F f);

// template<input_iterator I, sentinel_for<I> S, class T,
// indirectly-binary-left-foldable<T, I> F>
// constexpr see below ranges::fold_left(I first, S last, T init, F f);
//
// template<input_range R, class T, indirectly-binary-left-foldable<T, iterator_t<R>> F>
// constexpr see below ranges::fold_left(R&& r, T init, F f);

// Checks that the algorithm requirements reject parameters that don't meet the overloads' constraints.

#include <algorithm>
#include <concepts>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct ConvertibleFrom {
};

constexpr bool test() {
// Checks that conversion operations are correct.
{
std::ranges::in_found_result<double> res{10, true};
assert(res.in == 10);
Expand All @@ -72,6 +73,8 @@ constexpr bool test() {
assert(res2.in.content == 10);
assert(res2.found == true);
}

// Checks that conversions are possible when one of the types is move-only.
{
std::ranges::in_found_result<MoveOnly> res{MoveOnly{}, false};
assert(res.in.get() == 1);
Expand All @@ -82,10 +85,13 @@ constexpr bool test() {
assert(res.in.get() == 0);
assert(!res.found);
}
auto [in, found] = std::ranges::in_found_result<int>{2, false};
assert(in == 2);
assert(!found);

// Checks that structured bindings get the correct values.
{
auto [in, found] = std::ranges::in_found_result<int>{2, false};
assert(in == 2);
assert(!found);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static_assert(std::is_convertible_v<const std::ranges::in_fun_result<int, int>&&
static_assert(std::is_move_constructible_v<std::ranges::in_fun_result<MoveOnly, int>>);
static_assert(std::is_move_constructible_v<std::ranges::in_fun_result<int, MoveOnly>>);

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

Expand All @@ -64,6 +64,7 @@ struct ConvertibleFrom {
};

constexpr bool test() {
// Checks that conversion operations are correct.
{
std::ranges::in_fun_result<int, double> res{10, 0.};
assert(res.in == 10);
Expand All @@ -72,6 +73,8 @@ constexpr bool test() {
assert(res2.in.content == 10);
assert(res2.fun.content == 0.);
}

// Checks that conversions are possible when one of the types is move-only.
{
std::ranges::in_fun_result<MoveOnly, int> res{MoveOnly{}, 2};
assert(res.in.get() == 1);
Expand All @@ -81,6 +84,8 @@ constexpr bool test() {
assert(res2.in.get() == 1);
assert(res2.fun == 2);
}

// Checks that structured bindings get the correct values.
{
auto [in, fun] = std::ranges::in_fun_result<int, int>{1, 2};
assert(in == 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ struct ConvertibleFrom {
};

constexpr bool test() {
// Checks that conversion operations are correct.
{
std::ranges::in_in_out_result<int, double, float> res{10, 0., 1.f};
assert(res.in1 == 10);
Expand All @@ -77,13 +78,17 @@ constexpr bool test() {
assert(res2.in2.content == 0.);
assert(res2.out.content == 1.f);
}

// Checks that conversions are possible when one of the types is move-only.
{
std::ranges::in_in_out_result<MoveOnly, int, int> res1{MoveOnly{}, 0, 0};
assert(res1.in1.get() == 1);
auto res2 = static_cast<std::ranges::in_in_out_result<MoveOnly, int, int>>(std::move(res1));
assert(res1.in1.get() == 0);
assert(res2.in1.get() == 1);
}

// Checks that structured bindings get the correct values.
{
auto [in1, in2, out] = std::ranges::in_in_out_result<int, int, int>{1, 2, 3};
assert(in1 == 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct ConstructibleFrom {
};

constexpr bool test() {
// Checks that conversion operations are correct.
{
std::ranges::in_in_result<int, double> res{10L, 0.};
assert(res.in1 == 10);
Expand All @@ -67,12 +68,16 @@ constexpr bool test() {
assert(res2.in1.content == 10);
assert(res2.in2.content == 0.);
}

// Checks that conversions are possible when one of the types is move-only.
{
std::ranges::in_in_result<MoveOnly, int> res{MoveOnly{}, 0};
assert(res.in1.get() == 1);
[[maybe_unused]] auto res2 = static_cast<std::ranges::in_in_result<MoveOnly, int>>(std::move(res));
assert(res.in1.get() == 0);
}

// Checks that structured bindings get the correct values.
{
auto [in1, in2] = std::ranges::in_in_result<int, int>{1, 2};
assert(in1 == 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct ConvertibleFrom {
};

constexpr bool test() {
// Checks that conversion operations are correct.
{
std::ranges::in_out_out_result<int, double, float> res{10, 0., 1.f};
assert(res.in == 10);
Expand All @@ -75,13 +76,17 @@ constexpr bool test() {
assert(res2.out1.content == 0.);
assert(res2.out2.content == 1.f);
}

// Checks that conversions are possible when one of the types is move-only.
{
std::ranges::in_out_out_result<MoveOnly, int, int> res1{MoveOnly{}, 0, 0};
assert(res1.in.get() == 1);
auto res2 = static_cast<std::ranges::in_out_out_result<MoveOnly, int, int>>(std::move(res1));
assert(res1.in.get() == 0);
assert(res2.in.get() == 1);
}

// Checks that structured bindings get the correct values.
{
auto [in, out1, out2] = std::ranges::in_out_out_result<int, int, int>{1, 2, 3};
assert(in == 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct ConvertibleFrom {
};

constexpr bool test() {
// Checks that conversion operations are correct.
{
std::ranges::in_out_result<double, int> res{10, 1};
assert(res.in == 10);
Expand All @@ -67,6 +68,8 @@ constexpr bool test() {
assert(res2.in.content == 10);
assert(res2.out.content == 1);
}

// Checks that conversions are possible when one of the types is move-only.
{
std::ranges::in_out_result<MoveOnly, int> res{MoveOnly{}, 10};
assert(res.in.get() == 1);
Expand All @@ -77,6 +80,8 @@ constexpr bool test() {
assert(res2.in.get() == 1);
assert(res2.out == 10);
}

// Checks that structured bindings get the correct values.
{
auto [min, max] = std::ranges::in_out_result<int, int>{1, 2};
assert(min == 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static_assert(
static_assert(std::is_move_constructible_v<std::ranges::in_value_result<MoveOnly, int>>);
static_assert(std::is_move_constructible_v<std::ranges::in_value_result<int, MoveOnly>>);

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

Expand All @@ -71,6 +71,7 @@ struct ConvertibleFrom {
};

constexpr bool test() {
// Checks that conversion operations are correct.
{
std::ranges::in_value_result<int, double> res{10, 0.};
assert(res.in == 10);
Expand All @@ -79,6 +80,8 @@ constexpr bool test() {
assert(res2.in.content == 10);
assert(res2.value.content == 0.);
}

// Checks that conversions are possible when one of the types is move-only.
{
std::ranges::in_value_result<MoveOnly, int> res{MoveOnly{}, 2};
assert(res.in.get() == 1);
Expand All @@ -88,6 +91,8 @@ constexpr bool test() {
assert(res2.in.get() == 1);
assert(res2.value == 2);
}

// Checks that structured bindings get the correct values.
{
auto [in, value] = std::ranges::in_value_result<int, int>{1, 2};
assert(in == 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct ConvertibleFrom {
};

constexpr bool test() {
// Checks that conversion operations are correct.
{
std::ranges::min_max_result<double> res{10, 1};
assert(res.min == 10);
Expand All @@ -68,6 +69,8 @@ constexpr bool test() {
assert(res2.min.content == 10);
assert(res2.max.content == 1);
}

// Checks that conversions are possible when one of the types is move-only.
{
std::ranges::min_max_result<MoveOnly> res{MoveOnly{}, MoveOnly{}};
assert(res.min.get() == 1);
Expand All @@ -78,6 +81,8 @@ constexpr bool test() {
assert(res2.min.get() == 1);
assert(res2.max.get() == 1);
}

// Checks that structured bindings get the correct values.
{
auto [min, max] = std::ranges::min_max_result<int>{1, 2};
assert(min == 1);
Expand Down