Skip to content

[libc++] Add missing CPO tests for range adaptors #149557

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 6 commits into from
Jul 25, 2025
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 @@ -15,6 +15,7 @@
#include <concepts>
#include <iterator>
#include <ranges>
#include <sstream>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -45,7 +46,10 @@ constexpr bool test(CPO& o, Args&&...) {

int a[10];
int arrays[10][10];
//std::pair<int, int> pairs[10];
std::pair<int, int> pairs[10];
#ifndef TEST_HAS_NO_LOCALIZATION
std::istringstream stream;
#endif

// [concept.swappable]
static_assert(test(std::ranges::swap, a, a));
Expand Down Expand Up @@ -81,25 +85,50 @@ static_assert(test(std::ranges::ssize, a));
// views::empty<T> is not a CPO
static_assert(test(std::views::iota, 1));
static_assert(test(std::views::iota, 1, 10));
//static_assert(test(std::views::istream<int>, 1);
#ifndef TEST_HAS_NO_LOCALIZATION
static_assert(test(std::views::istream<int>, stream));
#endif
static_assert(test(std::views::single, 4));

#if TEST_STD_VER >= 23
static_assert(test(std::views::repeat, 1));
#endif

Comment on lines +93 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If tests are grouped by the C++ version, should this be moved down?

Copy link
Contributor

@frederick-vs-ja frederick-vs-ja Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think tests are intended to be grouped by sections ([range.factories], [range.adaptors]) first and then the standard modes. But this is up to @ldionne.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty neutral on this, but the tests were previously grouped as described by @frederick-vs-ja , so I decided to stick to that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this now, but I am happy to adjust as a NFC follow-up if we agree on another organization.

// [range.adaptors]
static_assert(test(std::views::all, a));
static_assert(test(std::views::common, a));
static_assert(test(std::views::counted, a, 10));
static_assert(test(std::views::drop, a, 10));
//static_assert(test(std::views::drop_while, a, [](int x){ return x < 10; }));
//static_assert(test(std::views::elements<0>, pairs));
static_assert(test(std::views::drop_while, a, [](int x) { return x < 10; }));
static_assert(test(std::views::elements<0>, pairs));
static_assert(test(std::views::filter, a, [](int x) { return x < 10; }));
static_assert(test(std::views::join, arrays));
//static_assert(test(std::views::split, a, 4));
static_assert(test(std::views::keys, pairs));
static_assert(test(std::views::lazy_split, a, 4));
static_assert(test(std::views::reverse, a));
static_assert(test(std::views::split, a, 4));
static_assert(test(std::views::take, a, 10));
//static_assert(test(std::views::take_while, a, [](int x){ return x < 10; }));
static_assert(test(std::views::take_while, a, [](int x) { return x < 10; }));
static_assert(test(std::views::transform, a, [](int x) { return x + 1; }));
static_assert(test(std::views::values, pairs));

#if TEST_STD_VER >= 23
// static_assert(test(std::views::adjacent_transform<2>, [](int x, int y) { return x + y; }, a));
// static_assert(test(std::views::adjacent<2>, a));
// static_assert(test(std::views::as_const, a));
static_assert(test(std::views::as_rvalue, a));
// static_assert(test(std::views::cartesian_product, a, a, a));
static_assert(test(std::views::chunk_by, a, [](int x, int y) { return x < y; }));
// static_assert(test(std::views::chunk, a, 1));
// static_assert(test(std::views::enumerate, a));
static_assert(test(std::views::join_with, 1));
// static_assert(test(std::views::stride, a, 1));
static_assert(test(std::views::zip_transform, [](int x, int y) { return x + y; }, a, a));
static_assert(test(std::views::zip, a, a));
#endif

#if TEST_STD_VER >= 26
// static_assert(test(std::views::cache_latest, a));
// static_assert(test(std::views::concat, a, a));
// static_assert(test(std::views::to_input, a));
#endif
Loading