Skip to content

[libc++][test] Fix zero-length arrays and copy-pasted lambdas in ranges.contains.pass.cpp #79792

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 3 commits into from
Jan 29, 2024
Merged
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 @@ -19,6 +19,7 @@
// constexpr bool ranges::contains(R&& r, const T& value, Proj proj = {}); // since C++23

#include <algorithm>
#include <array>
#include <cassert>
#include <list>
#include <ranges>
Expand Down Expand Up @@ -89,8 +90,8 @@ constexpr void test_iterators() {
}

{ // check that an empty range works
ValueT a[] = {};
auto whole = std::ranges::subrange(Iter(a), Sent(Iter(a)));
std::array<ValueT, 0> a = {};
auto whole = std::ranges::subrange(Iter(a.data()), Sent(Iter(a.data())));
{
bool ret = std::ranges::contains(whole.begin(), whole.end(), 1);
assert(!ret);
Expand Down Expand Up @@ -164,7 +165,7 @@ constexpr bool test() {
});
});

{ // count invocations of the projection for continuous iterators
{ // count invocations of the projection for contiguous iterators
int a[] = {1, 9, 0, 13, 25};
int projection_count = 0;
{
Expand Down Expand Up @@ -215,22 +216,22 @@ constexpr bool test() {
}
}

{ // check invocations of the projection for non-continuous iterators
{ // check invocations of the projection for non-contiguous iterators
std::vector<bool> whole{false, false, true, false};
int projection_count = 0;
{
bool ret = std::ranges::contains(whole.begin(), whole.end(), true, [&](int i) {
bool ret = std::ranges::contains(whole.begin(), whole.end(), true, [&](bool b) {
++projection_count;
return i;
return b;
});
assert(ret);
assert(projection_count == 3);
projection_count = 0;
}
{
bool ret = std::ranges::contains(whole, true, [&](int i) {
bool ret = std::ranges::contains(whole, true, [&](bool b) {
++projection_count;
return i;
return b;
});
assert(ret);
assert(projection_count == 3);
Expand Down