Skip to content

[libcxx][NFC] Consolidate testing concept CanBePiped #80154

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
Mar 8, 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 @@ -17,8 +17,9 @@
#include <type_traits>
#include <utility>

#include "test_macros.h"
#include "test_iterators.h"
#include "test_macros.h"
#include "test_range.h"

int globalBuff[8];

Expand Down Expand Up @@ -82,11 +83,6 @@ struct RandomAccessRange {
template<>
inline constexpr bool std::ranges::enable_borrowed_range<RandomAccessRange> = true;

template <class View, class T>
concept CanBePiped = requires (View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};

constexpr bool test() {
{
ASSERT_SAME_TYPE(decltype(std::views::all(View<true>())), View<true>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@
#include <utility>

#include "test_iterators.h"

template <class View, class T>
concept CanBePiped = requires(View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};
#include "test_range.h"

struct Pred {
constexpr bool operator()(int x, int y) const { return x != -y; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
#include <utility>

#include "test_iterators.h"
#include "test_range.h"
#include "types.h"

template <class View, class T>
concept CanBePiped = requires (View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};

constexpr bool test() {
int buf[] = {1, 2, 3};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <type_traits>
#include <utility>

#include "test_range.h"

struct Pred {
constexpr bool operator()(int i) const { return i < 3; }
};
Expand Down Expand Up @@ -51,12 +53,6 @@ static_assert(std::is_invocable_v<decltype((std::views::drop_while)), int (&)[2]
static_assert(!std::is_invocable_v<decltype((std::views::drop_while)), Foo (&)[2], Pred>);
static_assert(std::is_invocable_v<decltype((std::views::drop_while)), MoveOnlyView, Pred>);

template <class View, class T>
concept CanBePiped =
requires(View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};

static_assert(!CanBePiped<MoveOnlyView, decltype(std::views::drop_while)>);
static_assert(CanBePiped<MoveOnlyView, decltype(std::views::drop_while(Pred{}))>);
static_assert(!CanBePiped<int, decltype(std::views::drop_while(Pred{}))>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
#include <span>
#include <string_view>
#include <utility>
#include "test_iterators.h"

template <class View, class T>
concept CanBePiped = requires (View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};
#include "test_iterators.h"
#include "test_range.h"

struct SizedView : std::ranges::view_base {
int* begin_ = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <type_traits>
#include <utility>

#include "test_range.h"

template <class T>
struct View : std::ranges::view_base {
T* begin() const;
Expand All @@ -41,12 +43,6 @@ static_assert(!std::is_invocable_v<decltype((std::views::values)), View<int>>);
static_assert(std::is_invocable_v<decltype((std::views::values)), View<std::pair<int, int>>>);
static_assert(!std::is_invocable_v<decltype((std::views::values)), View<std::tuple<int>>>);

template <class View, class T>
concept CanBePiped =
requires(View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};

static_assert(!CanBePiped<View<int>, decltype((std::views::elements<0>))>);
static_assert(CanBePiped<View<std::pair<int, int>>, decltype((std::views::elements<0>))>);
static_assert(CanBePiped<View<std::tuple<int>>, decltype((std::views::elements<0>))>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
#include <utility>

#include "test_iterators.h"

template <class View, class T>
concept CanBePiped = requires (View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};
#include "test_range.h"

struct NonCopyablePredicate {
NonCopyablePredicate(NonCopyablePredicate const&) = delete;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <cassert>
#include <type_traits>

#include "test_range.h"
#include "types.h"

struct MoveOnlyOuter : SimpleForwardCommonOuter<ForwardCommonInner> {
Expand All @@ -32,11 +33,6 @@ struct Foo {
constexpr Foo(int ii) : i(ii) {}
};

template <class View, class T>
concept CanBePiped = requires(View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};

constexpr bool test() {
Copy link
Member

Choose a reason for hiding this comment

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

Include "test_range.h"? (or is it not used in this file?)

int buffer1[3] = {1, 2, 3};
int buffer2[2] = {4, 5};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@
#include <utility>

#include "test_iterators.h"
#include "test_range.h"
#include "types.h"

template <class View, class T>
concept CanBePiped = requires (View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};

struct SomeView : std::ranges::view_base {
const std::string_view* v_;
constexpr SomeView(const std::string_view& v) : v_(&v) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@
#include <iterator>
#include <utility>

#include "test_range.h"
#include "types.h"

template <class View, class T>
concept CanBePiped = requires (View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};

constexpr bool test() {
int buf[] = {1, 2, 3};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
#include <utility>

#include "test_iterators.h"

template <class View, class T>
concept CanBePiped = requires (View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};
#include "test_range.h"

struct SomeView : std::ranges::view_base {
const std::string_view* v_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <type_traits>
#include <utility>

#include "test_range.h"
#include "types.h"

struct Pred {
Expand All @@ -42,12 +43,6 @@ static_assert(std::is_invocable_v<decltype((std::views::take_while)), int (&)[2]
static_assert(!std::is_invocable_v<decltype((std::views::take_while)), Foo (&)[2], Pred>);
static_assert(std::is_invocable_v<decltype((std::views::take_while)), MoveOnlyView, Pred>);

template <class View, class T>
concept CanBePiped =
requires(View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};

static_assert(!CanBePiped<MoveOnlyView, decltype(std::views::take_while)>);
Copy link
Member

Choose a reason for hiding this comment

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

Include "test_range.h"? (or is it not used in this file?)

static_assert(CanBePiped<MoveOnlyView, decltype(std::views::take_while(Pred{}))>);
static_assert(!CanBePiped<int, decltype(std::views::take_while(Pred{}))>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@
#include <span>
#include <string_view>
#include <utility>
#include "test_iterators.h"

template <class View, class T>
concept CanBePiped = requires (View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};
#include "test_iterators.h"
#include "test_range.h"

struct SizedView : std::ranges::view_base {
int* begin_ = nullptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,9 @@
#include <utility>

#include "test_macros.h"
Copy link
Member

Choose a reason for hiding this comment

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

Do you need to include "test_range.h" here? Otherwise, this file is probably relying on a transitive include (unless CanBePiped is not used here?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great eyes! In these cases, I was relying on the fact that the implementers of the adapters created their own header files (types.h) and those file includes the test_range.h. I have adjusted the patch to make direct inclusion of the test_ranges.h file but I am more than happy to go back to the old version if that is our standard.

Thanks for the sharp feedback!

#include "test_range.h"
#include "types.h"

template <class View, class T>
concept CanBePiped = requires (View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};

struct NonCopyableFunction {
NonCopyableFunction(NonCopyableFunction const&) = delete;
template <class T>
Expand Down
5 changes: 5 additions & 0 deletions libcxx/test/support/test_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,9 @@ concept simple_view =
std::same_as<std::ranges::iterator_t<Range>, std::ranges::iterator_t<const Range>> &&
std::same_as<std::ranges::sentinel_t<Range>, std::ranges::sentinel_t<const Range>>;

template <class View, class T>
concept CanBePiped = requires(View&& view, T&& t) {
{ std::forward<View>(view) | std::forward<T>(t) };
};

#endif // LIBCXX_TEST_SUPPORT_TEST_RANGE_H