Skip to content

Commit 68ee310

Browse files
committed
[libcxx][NFC] Consolidate testing concept CanBePiped
Almost every test needed a CanBePiped concept and each implemented it separately, but identically. Consolidate all implementations into test_range.h.
1 parent a03a6e9 commit 68ee310

File tree

15 files changed

+21
-74
lines changed

15 files changed

+21
-74
lines changed

libcxx/test/std/ranges/range.adaptors/range.all/all.pass.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
#include <type_traits>
1818
#include <utility>
1919

20-
#include "test_macros.h"
2120
#include "test_iterators.h"
21+
#include "test_macros.h"
22+
#include "test_range.h"
2223

2324
int globalBuff[8];
2425

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

85-
template <class View, class T>
86-
concept CanBePiped = requires (View&& view, T&& t) {
87-
{ std::forward<View>(view) | std::forward<T>(t) };
88-
};
89-
9086
constexpr bool test() {
9187
{
9288
ASSERT_SAME_TYPE(decltype(std::views::all(View<true>())), View<true>);

libcxx/test/std/ranges/range.adaptors/range.chunk.by/adaptor.pass.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@
2222
#include <utility>
2323

2424
#include "test_iterators.h"
25-
26-
template <class View, class T>
27-
concept CanBePiped = requires(View&& view, T&& t) {
28-
{ std::forward<View>(view) | std::forward<T>(t) };
29-
};
25+
#include "test_range.h"
3026

3127
struct Pred {
3228
constexpr bool operator()(int x, int y) const { return x != -y; }

libcxx/test/std/ranges/range.adaptors/range.common.view/adaptor.pass.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,9 @@
1818
#include <utility>
1919

2020
#include "test_iterators.h"
21+
#include "test_range.h"
2122
#include "types.h"
2223

23-
template <class View, class T>
24-
concept CanBePiped = requires (View&& view, T&& t) {
25-
{ std::forward<View>(view) | std::forward<T>(t) };
26-
};
27-
2824
constexpr bool test() {
2925
int buf[] = {1, 2, 3};
3026

libcxx/test/std/ranges/range.adaptors/range.drop.while/adaptor.pass.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include <type_traits>
1717
#include <utility>
1818

19+
#include "test_range.h"
20+
1921
struct Pred {
2022
constexpr bool operator()(int i) const { return i < 3; }
2123
};
@@ -51,12 +53,6 @@ static_assert(std::is_invocable_v<decltype((std::views::drop_while)), int (&)[2]
5153
static_assert(!std::is_invocable_v<decltype((std::views::drop_while)), Foo (&)[2], Pred>);
5254
static_assert(std::is_invocable_v<decltype((std::views::drop_while)), MoveOnlyView, Pred>);
5355

54-
template <class View, class T>
55-
concept CanBePiped =
56-
requires(View&& view, T&& t) {
57-
{ std::forward<View>(view) | std::forward<T>(t) };
58-
};
59-
6056
static_assert(!CanBePiped<MoveOnlyView, decltype(std::views::drop_while)>);
6157
static_assert(CanBePiped<MoveOnlyView, decltype(std::views::drop_while(Pred{}))>);
6258
static_assert(!CanBePiped<int, decltype(std::views::drop_while(Pred{}))>);

libcxx/test/std/ranges/range.adaptors/range.drop/adaptor.pass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818
#include <span>
1919
#include <string_view>
2020
#include <utility>
21-
#include "test_iterators.h"
2221

23-
template <class View, class T>
24-
concept CanBePiped = requires (View&& view, T&& t) {
25-
{ std::forward<View>(view) | std::forward<T>(t) };
26-
};
22+
#include "test_iterators.h"
23+
#include "test_range.h"
2724

2825
struct SizedView : std::ranges::view_base {
2926
int* begin_ = nullptr;

libcxx/test/std/ranges/range.adaptors/range.elements/adaptor.pass.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <type_traits>
2020
#include <utility>
2121

22+
#include "test_range.h"
23+
2224
template <class T>
2325
struct View : std::ranges::view_base {
2426
T* begin() const;
@@ -41,12 +43,6 @@ static_assert(!std::is_invocable_v<decltype((std::views::values)), View<int>>);
4143
static_assert(std::is_invocable_v<decltype((std::views::values)), View<std::pair<int, int>>>);
4244
static_assert(!std::is_invocable_v<decltype((std::views::values)), View<std::tuple<int>>>);
4345

44-
template <class View, class T>
45-
concept CanBePiped =
46-
requires(View&& view, T&& t) {
47-
{ std::forward<View>(view) | std::forward<T>(t) };
48-
};
49-
5046
static_assert(!CanBePiped<View<int>, decltype((std::views::elements<0>))>);
5147
static_assert(CanBePiped<View<std::pair<int, int>>, decltype((std::views::elements<0>))>);
5248
static_assert(CanBePiped<View<std::tuple<int>>, decltype((std::views::elements<0>))>);

libcxx/test/std/ranges/range.adaptors/range.filter/adaptor.pass.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
#include <utility>
2020

2121
#include "test_iterators.h"
22-
23-
template <class View, class T>
24-
concept CanBePiped = requires (View&& view, T&& t) {
25-
{ std::forward<View>(view) | std::forward<T>(t) };
26-
};
22+
#include "test_range.h"
2723

2824
struct NonCopyablePredicate {
2925
NonCopyablePredicate(NonCopyablePredicate const&) = delete;

libcxx/test/std/ranges/range.adaptors/range.join/adaptor.pass.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ struct Foo {
3232
constexpr Foo(int ii) : i(ii) {}
3333
};
3434

35-
template <class View, class T>
36-
concept CanBePiped = requires(View&& view, T&& t) {
37-
{ std::forward<View>(view) | std::forward<T>(t) };
38-
};
39-
4035
constexpr bool test() {
4136
int buffer1[3] = {1, 2, 3};
4237
int buffer2[2] = {4, 5};

libcxx/test/std/ranges/range.adaptors/range.lazy.split/adaptor.pass.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@
1919
#include <utility>
2020

2121
#include "test_iterators.h"
22+
#include "test_range.h"
2223
#include "types.h"
2324

24-
template <class View, class T>
25-
concept CanBePiped = requires (View&& view, T&& t) {
26-
{ std::forward<View>(view) | std::forward<T>(t) };
27-
};
28-
2925
struct SomeView : std::ranges::view_base {
3026
const std::string_view* v_;
3127
constexpr SomeView(const std::string_view& v) : v_(&v) {}

libcxx/test/std/ranges/range.adaptors/range.reverse/adaptor.pass.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717
#include <iterator>
1818
#include <utility>
1919

20+
#include "test_range.h"
2021
#include "types.h"
2122

22-
template <class View, class T>
23-
concept CanBePiped = requires (View&& view, T&& t) {
24-
{ std::forward<View>(view) | std::forward<T>(t) };
25-
};
26-
2723
constexpr bool test() {
2824
int buf[] = {1, 2, 3};
2925

libcxx/test/std/ranges/range.adaptors/range.split/adaptor.pass.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
#include <utility>
2020

2121
#include "test_iterators.h"
22-
23-
template <class View, class T>
24-
concept CanBePiped = requires (View&& view, T&& t) {
25-
{ std::forward<View>(view) | std::forward<T>(t) };
26-
};
22+
#include "test_range.h"
2723

2824
struct SomeView : std::ranges::view_base {
2925
const std::string_view* v_;

libcxx/test/std/ranges/range.adaptors/range.take.while/adaptor.pass.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ static_assert(std::is_invocable_v<decltype((std::views::take_while)), int (&)[2]
4242
static_assert(!std::is_invocable_v<decltype((std::views::take_while)), Foo (&)[2], Pred>);
4343
static_assert(std::is_invocable_v<decltype((std::views::take_while)), MoveOnlyView, Pred>);
4444

45-
template <class View, class T>
46-
concept CanBePiped =
47-
requires(View&& view, T&& t) {
48-
{ std::forward<View>(view) | std::forward<T>(t) };
49-
};
50-
5145
static_assert(!CanBePiped<MoveOnlyView, decltype(std::views::take_while)>);
5246
static_assert(CanBePiped<MoveOnlyView, decltype(std::views::take_while(Pred{}))>);
5347
static_assert(!CanBePiped<int, decltype(std::views::take_while(Pred{}))>);

libcxx/test/std/ranges/range.adaptors/range.take/adaptor.pass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717
#include <span>
1818
#include <string_view>
1919
#include <utility>
20-
#include "test_iterators.h"
2120

22-
template <class View, class T>
23-
concept CanBePiped = requires (View&& view, T&& t) {
24-
{ std::forward<View>(view) | std::forward<T>(t) };
25-
};
21+
#include "test_iterators.h"
22+
#include "test_range.h"
2623

2724
struct SizedView : std::ranges::view_base {
2825
int* begin_ = nullptr;

libcxx/test/std/ranges/range.adaptors/range.transform/adaptor.pass.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020
#include "test_macros.h"
2121
#include "types.h"
2222

23-
template <class View, class T>
24-
concept CanBePiped = requires (View&& view, T&& t) {
25-
{ std::forward<View>(view) | std::forward<T>(t) };
26-
};
27-
2823
struct NonCopyableFunction {
2924
NonCopyableFunction(NonCopyableFunction const&) = delete;
3025
template <class T>

libcxx/test/support/test_range.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,9 @@ concept simple_view =
8989
std::same_as<std::ranges::iterator_t<Range>, std::ranges::iterator_t<const Range>> &&
9090
std::same_as<std::ranges::sentinel_t<Range>, std::ranges::sentinel_t<const Range>>;
9191

92+
template <class View, class T>
93+
concept CanBePiped = requires(View&& view, T&& t) {
94+
{ std::forward<View>(view) | std::forward<T>(t) };
95+
};
96+
9297
#endif // LIBCXX_TEST_SUPPORT_TEST_RANGE_H

0 commit comments

Comments
 (0)