Skip to content

Commit 8a61095

Browse files
committed
test view::begin()
1 parent ea66101 commit 8a61095

File tree

2 files changed

+44
-48
lines changed

2 files changed

+44
-48
lines changed

libcxx/test/std/ranges/range.adaptors/range.cartesian.product.view/begin.pass.cpp

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
// constexpr iterator<true > begin() const requires (range<const First> && ... && range<const Vs>);
1313

1414
#include <ranges>
15-
16-
// #include <cassert>
17-
// #include <concepts>
18-
// #include <tuple>
19-
// #include <utility>
15+
#include <cassert>
16+
#include <concepts>
17+
#include <tuple>
18+
#include <utility>
2019

2120
#include "types.h"
2221

@@ -27,17 +26,17 @@ template <class T>
2726
concept HasNonConstBegin = requires(T& t) { t.begin(); };
2827

2928
template <class T>
30-
concept HasConstAndNonConstBegin =
31-
HasConstBegin<T> && HasNonConstBegin<T> &&
32-
requires(T& t, const T& ct) { requires !std::same_as<decltype(t.begin()), decltype(ct.begin())>; };
29+
concept HasConstAndNonConstBegin = HasConstBegin<T> && HasNonConstBegin<T> && requires(T& t, const T& ct) {
30+
requires !std::same_as<decltype(t.begin()), decltype(ct.begin())>;
31+
};
3332

3433
template <class T>
3534
concept HasOnlyNonConstBegin = HasNonConstBegin<T> && !HasConstBegin<T>;
3635

3736
template <class T>
3837
concept HasOnlyConstBegin = HasConstBegin<T> && !HasConstAndNonConstBegin<T>;
3938

40-
struct OnlyNonConstBeginView : std::ranges::view_base {
39+
struct NoConstBeginView : std::ranges::view_base {
4140
int* begin();
4241
int* end();
4342
};
@@ -73,8 +72,7 @@ constexpr bool test() {
7372
}
7473
}
7574

76-
{
77-
// underlying ranges all model simple-view
75+
{ // underlying ranges all model simple-view
7876
std::ranges::cartesian_product_view v(SimpleCommon{buffer}, SimpleCommon{buffer});
7977
static_assert(std::is_same_v<decltype(v.begin()), decltype(std::as_const(v).begin())>);
8078
assert(v.begin() == std::as_const(v).begin());
@@ -89,28 +87,26 @@ constexpr bool test() {
8987
static_assert(!HasConstAndNonConstBegin<View>);
9088
}
9189

92-
// {
93-
// // not all underlying ranges model simple-view
94-
// std::ranges::zip_view v(SimpleCommon{buffer}, NonSimpleNonCommon{buffer});
95-
// static_assert(!std::is_same_v<decltype(v.begin()), decltype(std::as_const(v).begin())>);
96-
// assert(v.begin() == std::as_const(v).begin());
97-
// auto [x, y] = *std::as_const(v).begin();
98-
// assert(&x == &buffer[0]);
99-
// assert(&y == &buffer[0]);
100-
101-
// using View = decltype(v);
102-
// static_assert(!HasOnlyConstBegin<View>);
103-
// static_assert(!HasOnlyNonConstBegin<View>);
104-
// static_assert(HasConstAndNonConstBegin<View>);
105-
// }
106-
107-
// {
108-
// // underlying const R is not a range
109-
// using View = std::ranges::zip_view<SimpleCommon, NoConstBeginView>;
110-
// static_assert(!HasOnlyConstBegin<View>);
111-
// static_assert(HasOnlyNonConstBegin<View>);
112-
// static_assert(!HasConstAndNonConstBegin<View>);
113-
// }
90+
{ // not all underlying ranges model simple-view
91+
std::ranges::cartesian_product_view v(SimpleCommon{buffer}, NonSimpleNonCommon{buffer});
92+
static_assert(!std::is_same_v<decltype(v.begin()), decltype(std::as_const(v).begin())>);
93+
assert(v.begin() == std::as_const(v).begin());
94+
auto [x, y] = *std::as_const(v).begin();
95+
assert(&x == &buffer[0]);
96+
assert(&y == &buffer[0]);
97+
98+
using View = decltype(v);
99+
static_assert(!HasOnlyConstBegin<View>);
100+
static_assert(!HasOnlyNonConstBegin<View>);
101+
static_assert(HasConstAndNonConstBegin<View>);
102+
}
103+
104+
{ // underlying const R is not a range
105+
using View = std::ranges::cartesian_product_view<SimpleCommon, NoConstBeginView>;
106+
static_assert(!HasOnlyConstBegin<View>);
107+
static_assert(HasOnlyNonConstBegin<View>);
108+
static_assert(!HasConstAndNonConstBegin<View>);
109+
}
114110
return true;
115111
}
116112

libcxx/test/std/ranges/range.adaptors/range.cartesian.product.view/types.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,23 @@ using SimpleCommon = Common<true>;
8686
// static_assert(simple_view<SimpleCommonNonRandom>);
8787
// static_assert(!simple_view<NonSimpleCommonNonRandom>);
8888

89-
// template <bool Simple>
90-
// struct NonCommon : IntBufferView {
91-
// using IntBufferView::IntBufferView;
92-
// constexpr int* begin()
93-
// requires(!Simple) {
94-
// return buffer_;
95-
// }
96-
// constexpr const int* begin() const { return buffer_; }
97-
// constexpr sentinel_wrapper<int*> end()
98-
// requires(!Simple) {
99-
// return sentinel_wrapper<int*>(buffer_ + size_);
100-
// }
101-
// constexpr sentinel_wrapper<const int*> end() const { return sentinel_wrapper<const int*>(buffer_ + size_); }
102-
// };
89+
template <bool Simple>
90+
struct NonCommon : IntBufferView {
91+
using IntBufferView::IntBufferView;
92+
constexpr int* begin()
93+
requires(!Simple) {
94+
return buffer_;
95+
}
96+
constexpr const int* begin() const { return buffer_; }
97+
constexpr sentinel_wrapper<int*> end()
98+
requires(!Simple) {
99+
return sentinel_wrapper<int*>(buffer_ + size_);
100+
}
101+
constexpr sentinel_wrapper<const int*> end() const { return sentinel_wrapper<const int*>(buffer_ + size_); }
102+
};
103103

104104
// using SimpleNonCommon = NonCommon<true>;
105-
// using NonSimpleNonCommon = NonCommon<false>;
105+
using NonSimpleNonCommon = NonCommon<false>;
106106

107107
// static_assert(!std::ranges::common_range<SimpleNonCommon>);
108108
// static_assert(std::ranges::random_access_range<SimpleNonCommon>);

0 commit comments

Comments
 (0)