Skip to content

Commit e81c66b

Browse files
different types
1 parent 13cbe33 commit e81c66b

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

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

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
#include "test_iterators.h"
1616
#include "test_range.h"
1717

18-
struct Range : std::ranges::view_base {
18+
struct ForwardRange : std::ranges::view_base {
1919
using Iterator = forward_iterator<int*>;
2020
using Sentinel = sentinel_wrapper<Iterator>;
21-
constexpr explicit Range(int* b, int* e) : begin_(b), end_(e) {}
21+
constexpr explicit ForwardRange(int* b, int* e) : begin_(b), end_(e) {}
2222
constexpr Iterator begin() const { return Iterator(begin_); }
2323
constexpr Sentinel end() const { return Sentinel(Iterator(end_)); }
2424

@@ -27,6 +27,17 @@ struct Range : std::ranges::view_base {
2727
int* end_;
2828
};
2929

30+
struct BidirectionalRange : std::ranges::view_base {
31+
using Iterator = bidirectional_iterator<int*>;
32+
using Sentinel = sentinel_wrapper<Iterator>;
33+
constexpr explicit BidirectionalRange(int* b, int* e): begin_(b), end_(e) {}
34+
constexpr Iterator begin() const { return Iterator(begin_); }
35+
constexpr Sentinel end() const { return Sentinel(Iterator(end_)); }
36+
private:
37+
int* begin_;
38+
int* end_;
39+
};
40+
3041
template <typename View>
3142
constexpr void compareViews(View v, std::initializer_list<int> list) {
3243
auto b1 = v.begin();
@@ -46,8 +57,9 @@ constexpr bool test() {
4657
int arr[] = {0, 1, 2, 3};
4758
int arr2[] = {4, 5, 6, 7};
4859

60+
// one range
4961
{
50-
Range range(arr, arr + 4);
62+
ForwardRange range(arr, arr + 4);
5163

5264
{
5365
decltype(auto) result = std::views::concat(range);
@@ -56,14 +68,27 @@ constexpr bool test() {
5668
}
5769
}
5870

71+
// more than one range of same types
5972
{
60-
Range first(arr, arr + 4);
61-
Range tail(arr2, arr2 + 4);
73+
ForwardRange first(arr, arr + 4);
74+
ForwardRange tail(arr2, arr2 + 4);
6275

6376
{
6477
decltype(auto) result = std::views::concat(first, tail);
6578
compareViews(result, {0, 1, 2, 3, 4, 5, 6, 7});
66-
using Type = std::ranges::concat_view<Range, Range>;
79+
using Type = std::ranges::concat_view<ForwardRange, ForwardRange>;
80+
ASSERT_SAME_TYPE(Type, decltype(result));
81+
}
82+
}
83+
84+
// more than one range of different types
85+
{
86+
ForwardRange first(arr, arr + 4);
87+
BidirectionalRange tail(arr2, arr2 + 4);
88+
{
89+
decltype(auto) result = std::views::concat(first, tail);
90+
compareViews(result, {0, 1, 2, 3, 4, 5, 6, 7});
91+
using Type = std::ranges::concat_view<ForwardRange, BidirectionalRange>;
6792
ASSERT_SAME_TYPE(Type, decltype(result));
6893
}
6994
}

0 commit comments

Comments
 (0)