Skip to content

Commit 2705669

Browse files
committed
review
1 parent 37a4e85 commit 2705669

File tree

12 files changed

+135
-142
lines changed

12 files changed

+135
-142
lines changed

libcxx/include/__ranges/adjacent_view.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class adjacent_view<_View, _Np>::__iterator {
191191

192192
_LIBCPP_HIDE_FROM_ABI __iterator() = default;
193193
_LIBCPP_HIDE_FROM_ABI constexpr __iterator(__iterator<!_Const> __i)
194-
requires _Const && convertible_to<iterator_t<_View>, iterator_t<_Base>>
194+
requires _Const && convertible_to<iterator_t<_View>, iterator_t<const _View>>
195195
: __iterator(std::move(__i), make_index_sequence<_Np>{}) {}
196196

197197
_LIBCPP_HIDE_FROM_ABI constexpr auto operator*() const {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ constexpr void test_all_constraints() {
4848
test_constraints<5>();
4949
}
5050

51-
constexpr void test_zero_case() {
51+
static constexpr void test_zero_case() {
5252
// N == 0 is a special case that always results in an empty range
5353
int buffer[8] = {1, 2, 3, 4, 5, 6, 7, 8};
5454

libcxx/test/std/ranges/range.adaptors/range.adjacent/begin.pass.cpp

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,26 +91,21 @@ constexpr void test_one() {
9191
}
9292
}
9393

94-
template <std::size_t N>
95-
constexpr void test_simple() {
96-
test_one<SimpleCommon, N>();
97-
98-
using View = std::ranges::adjacent_view<SimpleCommon, N>;
99-
static_assert(std::is_same_v<std::ranges::iterator_t<View>, std::ranges::iterator_t<const View>>);
100-
}
101-
102-
template <std::size_t N>
103-
constexpr void test_non_simple() {
104-
test_one<NonSimpleCommon, N>();
105-
106-
using View = std::ranges::adjacent_view<NonSimpleCommon, N>;
107-
static_assert(!std::is_same_v<std::ranges::iterator_t<View>, std::ranges::iterator_t<const View>>);
108-
}
109-
11094
template <std::size_t N>
11195
constexpr void test() {
112-
test_simple<N>();
113-
test_non_simple<N>();
96+
{
97+
// Test with simple view
98+
test_one<SimpleCommon, N>();
99+
using View = std::ranges::adjacent_view<SimpleCommon, N>;
100+
static_assert(std::is_same_v<std::ranges::iterator_t<View>, std::ranges::iterator_t<const View>>);
101+
}
102+
103+
{
104+
// Test with non-simple view
105+
test_one<NonSimpleCommon, N>();
106+
using View = std::ranges::adjacent_view<NonSimpleCommon, N>;
107+
static_assert(!std::is_same_v<std::ranges::iterator_t<View>, std::ranges::iterator_t<const View>>);
108+
}
114109

115110
// Test with view that doesn't support const begin()
116111
using ViewWithNoConstBegin = std::ranges::adjacent_view<NoConstBeginView, N>;

libcxx/test/std/ranges/range.adaptors/range.adjacent/ctor.views.pass.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct MoveAwareView : std::ranges::view_base {
4242
};
4343

4444
template <class View, std::size_t N>
45-
constexpr void constructorTest(auto&& buffer) {
45+
constexpr void constructor_test(auto&& buffer) {
4646
std::ranges::adjacent_view<View, N> v{View{buffer}};
4747
auto tuple = *v.begin();
4848
assert(std::get<0>(tuple) == buffer[0]);
@@ -66,22 +66,22 @@ constexpr void test() {
6666

6767
// forward
6868
{
69-
constructorTest<ForwardSizedView, N>(buffer);
69+
constructor_test<ForwardSizedView, N>(buffer);
7070
}
7171

7272
// bidi
7373
{
74-
constructorTest<BidiCommonView, N>(buffer);
74+
constructor_test<BidiCommonView, N>(buffer);
7575
}
7676

7777
// random_access
7878
{
79-
constructorTest<SizedRandomAccessView, N>(buffer);
79+
constructor_test<SizedRandomAccessView, N>(buffer);
8080
}
8181

8282
// contiguous
8383
{
84-
constructorTest<ContiguousCommonView, N>(buffer);
84+
constructor_test<ContiguousCommonView, N>(buffer);
8585
}
8686
}
8787

libcxx/test/std/ranges/range.adaptors/range.adjacent/end.pass.cpp

Lines changed: 49 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -93,75 +93,67 @@ constexpr void test_decrement_back() {
9393
}
9494

9595
template <std::size_t N>
96-
constexpr void test_simple_common_types() {
97-
using NonConstView = std::ranges::adjacent_view<SimpleCommon, N>;
98-
using ConstView = const NonConstView;
99-
100-
static_assert(std::ranges::common_range<NonConstView>);
101-
static_assert(std::ranges::common_range<ConstView>);
102-
static_assert(std::is_same_v<std::ranges::sentinel_t<NonConstView>, std::ranges::sentinel_t<ConstView>>);
103-
104-
test_one<SimpleCommon, N>();
105-
test_decrement_back<SimpleCommon, N>();
106-
}
107-
108-
template <std::size_t N>
109-
constexpr void test_simple_non_common_types() {
110-
using NonConstView = std::ranges::adjacent_view<SimpleNonCommon, N>;
111-
using ConstView = const NonConstView;
96+
constexpr void test() {
97+
{
98+
// simple common
99+
using NonConstView = std::ranges::adjacent_view<SimpleCommon, N>;
100+
using ConstView = const NonConstView;
112101

113-
static_assert(!std::ranges::common_range<NonConstView>);
114-
static_assert(!std::ranges::common_range<ConstView>);
115-
static_assert(std::is_same_v<std::ranges::sentinel_t<NonConstView>, std::ranges::sentinel_t<ConstView>>);
102+
static_assert(std::ranges::common_range<NonConstView>);
103+
static_assert(std::ranges::common_range<ConstView>);
104+
static_assert(std::is_same_v<std::ranges::sentinel_t<NonConstView>, std::ranges::sentinel_t<ConstView>>);
116105

117-
test_one<SimpleNonCommon, N>();
118-
}
106+
test_one<SimpleCommon, N>();
107+
test_decrement_back<SimpleCommon, N>();
108+
}
109+
{
110+
// simple non common
119111

120-
template <std::size_t N>
121-
constexpr void test_non_simple_common_types() {
122-
using NonConstView = std::ranges::adjacent_view<NonSimpleCommon, N>;
123-
using ConstView = const NonConstView;
112+
using NonConstView = std::ranges::adjacent_view<SimpleNonCommon, N>;
113+
using ConstView = const NonConstView;
124114

125-
static_assert(std::ranges::common_range<NonConstView>);
126-
static_assert(std::ranges::common_range<ConstView>);
127-
static_assert(!std::is_same_v<std::ranges::sentinel_t<NonConstView>, std::ranges::sentinel_t<ConstView>>);
115+
static_assert(!std::ranges::common_range<NonConstView>);
116+
static_assert(!std::ranges::common_range<ConstView>);
117+
static_assert(std::is_same_v<std::ranges::sentinel_t<NonConstView>, std::ranges::sentinel_t<ConstView>>);
128118

129-
test_one<NonSimpleCommon, N>();
130-
test_decrement_back<NonSimpleCommon, N>();
131-
}
119+
test_one<SimpleNonCommon, N>();
120+
}
132121

133-
template <std::size_t N>
134-
constexpr void test_non_simple_non_common_types() {
135-
using NonConstView = std::ranges::adjacent_view<NonSimpleNonCommon, N>;
136-
using ConstView = const NonConstView;
122+
{
123+
// non simple common
124+
using NonConstView = std::ranges::adjacent_view<NonSimpleCommon, N>;
125+
using ConstView = const NonConstView;
137126

138-
static_assert(!std::ranges::common_range<NonConstView>);
139-
static_assert(!std::ranges::common_range<ConstView>);
140-
static_assert(!std::is_same_v<std::ranges::sentinel_t<NonConstView>, std::ranges::sentinel_t<ConstView>>);
127+
static_assert(std::ranges::common_range<NonConstView>);
128+
static_assert(std::ranges::common_range<ConstView>);
129+
static_assert(!std::is_same_v<std::ranges::sentinel_t<NonConstView>, std::ranges::sentinel_t<ConstView>>);
141130

142-
test_one<NonSimpleNonCommon, N>();
143-
}
131+
test_one<NonSimpleCommon, N>();
132+
test_decrement_back<NonSimpleCommon, N>();
133+
}
134+
{
135+
// non simple non common
136+
using NonConstView = std::ranges::adjacent_view<NonSimpleNonCommon, N>;
137+
using ConstView = const NonConstView;
144138

145-
template <std::size_t N>
146-
constexpr void test_forward_only() {
147-
using NonConstView = std::ranges::adjacent_view<NonSimpleForwardSizedNonCommon, N>;
148-
using ConstView = const NonConstView;
139+
static_assert(!std::ranges::common_range<NonConstView>);
140+
static_assert(!std::ranges::common_range<ConstView>);
141+
static_assert(!std::is_same_v<std::ranges::sentinel_t<NonConstView>, std::ranges::sentinel_t<ConstView>>);
149142

150-
static_assert(!std::ranges::common_range<NonConstView>);
151-
static_assert(!std::ranges::common_range<ConstView>);
152-
static_assert(!std::is_same_v<std::ranges::sentinel_t<NonConstView>, std::ranges::sentinel_t<ConstView>>);
143+
test_one<NonSimpleNonCommon, N>();
144+
}
145+
{
146+
// forward only
147+
using NonConstView = std::ranges::adjacent_view<NonSimpleForwardSizedNonCommon, N>;
148+
using ConstView = const NonConstView;
153149

154-
test_one<NonSimpleForwardSizedNonCommon, N>();
155-
test_one<ForwardSizedView, N>();
156-
}
150+
static_assert(!std::ranges::common_range<NonConstView>);
151+
static_assert(!std::ranges::common_range<ConstView>);
152+
static_assert(!std::is_same_v<std::ranges::sentinel_t<NonConstView>, std::ranges::sentinel_t<ConstView>>);
157153

158-
template <std::size_t N>
159-
constexpr void test() {
160-
test_simple_common_types<N>();
161-
test_simple_non_common_types<N>();
162-
test_non_simple_common_types<N>();
163-
test_non_simple_non_common_types<N>();
164-
test_forward_only<N>();
154+
test_one<NonSimpleForwardSizedNonCommon, N>();
155+
test_one<ForwardSizedView, N>();
156+
}
165157
}
166158

167159
constexpr bool test() {

libcxx/test/std/ranges/range.adaptors/range.adjacent/helpers.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
#include <tuple>
1313

14-
// intentionally not using meta programming for the expected tuple types
14+
// We intentionally don't use metaprogramming to define the expected tuple types
15+
// because otherwise the test code would be basically the same as the source code
16+
// we're trying to test.
1517

1618
template <std::size_t N, class T>
1719
struct ExpectedTupleType;
@@ -40,4 +42,4 @@ struct ExpectedTupleType<5, T> {
4042
template <std::size_t N, class T>
4143
using expectedTupleType = typename ExpectedTupleType<N, T>::type;
4244

43-
#endif // TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_ADJACENT_HELPERS_H
45+
#endif // TEST_STD_RANGES_RANGE_ADAPTORS_RANGE_ADJACENT_HELPERS_H

libcxx/test/std/ranges/range.adaptors/range.adjacent/iterator/ctor.default.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "../../range_adaptor_types.h"
1717

1818
struct PODIter {
19-
int i; // deliberately uninitialised
19+
int i; // deliberately uninitialised because we're testing that default ctor of the iterator zero initialises the underlying iterators
2020

2121
using iterator_category = std::random_access_iterator_tag;
2222
using value_type = int;

libcxx/test/std/ranges/range.adaptors/range.adjacent/iterator/ctor.other.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1010

1111
// constexpr iterator(iterator<!Const> i)
12-
// requires Const && convertible_to<iterator_t<V>, iterator_t<Base>>;
12+
// requires Const && convertible_to<iterator_t<V>, iterator_t<const V>>;
1313

1414
#include <ranges>
1515

libcxx/test/std/ranges/range.adaptors/range.adjacent/iterator/member_types.compile.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,4 @@ void test() {
147147
test<2>();
148148
test<3>();
149149
test<5>();
150-
}
150+
}

libcxx/test/std/ranges/range.adaptors/range.adjacent/iterator/singular.pass.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
1010
// UNSUPPORTED: no-exceptions
1111

12-
// If the invocation of any non-const member function of `iterator` exits via an
12+
// [range.adjacent.iterator#2] If the invocation of any non-const member function of `iterator` exits via an
1313
// exception, the iterator acquires a singular value.
1414

1515
#include <ranges>
@@ -64,10 +64,11 @@ void test() {
6464
} catch (int e) {
6565
assert(e == 5);
6666
}
67+
// destroy the iterator
6768
}
6869

6970
{
70-
// adjacent_view iterator should be able to be assigned after member function throws
71+
// adjacent_view iterator should be assignable after member function throws
7172
auto v = ThrowOnIncrementView{buffer} | std::views::adjacent<N>;
7273
auto it = v.begin();
7374
++it;

0 commit comments

Comments
 (0)