Skip to content

Commit 930a9cb

Browse files
Address some review comments
- Templatize `test_basic_operations`. - Assert noexcept-ness. - Change notes in implementation status.
1 parent d22a25d commit 930a9cb

File tree

3 files changed

+60
-50
lines changed

3 files changed

+60
-50
lines changed

libcxx/docs/Status/Cxx2cPapers.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"`P2819R2 <https://wg21.link/P2819R2>`__","Add tuple protocol to complex","2023-11 (Kona)","|Complete|","19",""
4343
"`P2937R0 <https://wg21.link/P2937R0>`__","Freestanding: Remove ``strtok``","2023-11 (Kona)","","",""
4444
"`P2833R2 <https://wg21.link/P2833R2>`__","Freestanding Library: inout expected span","2023-11 (Kona)","","",""
45-
"`P2836R1 <https://wg21.link/P2836R1>`__","``std::basic_const_iterator`` should follow its underlying type's convertibility","2023-11 (Kona)","|Complete|","21","Implemented as a DR against C++23. (MSVC STL and libstdc++ will do the same.)"
45+
"`P2836R1 <https://wg21.link/P2836R1>`__","``std::basic_const_iterator`` should follow its underlying type's convertibility","2023-11 (Kona)","|Complete|","21","Implemented as a DR against C++23. (MSVC STL and libstdc++ do the same.)"
4646
"`P2264R7 <https://wg21.link/P2264R7>`__","Make ``assert()`` macro user friendly for C and C++","2023-11 (Kona)","","",""
4747
"`P1673R13 <https://wg21.link/P1673R13>`__","A free function linear algebra interface based on the BLAS","2023-11 (Kona)","","",""
4848
"","","","","",""

libcxx/include/__ranges/const_access.h

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2929

3030
#if _LIBCPP_STD_VER >= 20
3131

32+
namespace ranges {
3233
// [range.const]
3334
# if _LIBCPP_STD_VER >= 23
34-
namespace ranges {
3535
template <input_range _Rp>
3636
_LIBCPP_HIDE_FROM_ABI constexpr auto& __possibly_const_range(_Rp& __rng) noexcept {
3737
if constexpr (input_range<const _Rp>) {
@@ -40,11 +40,9 @@ _LIBCPP_HIDE_FROM_ABI constexpr auto& __possibly_const_range(_Rp& __rng) noexcep
4040
return __rng;
4141
}
4242
}
43-
} // namespace ranges
4443
# endif // _LIBCPP_STD_VER >= 23
4544

4645
// [range.access.cbegin]
47-
namespace ranges {
4846

4947
template <class _Type>
5048
concept __const_accessible_range = (!is_rvalue_reference_v<_Type&&> || enable_borrowed_range<remove_cv_t<_Type>>);
@@ -84,18 +82,15 @@ struct __fn {
8482
inline namespace __cpo {
8583
inline constexpr auto cbegin = __cbegin::__fn{};
8684
} // namespace __cpo
87-
} // namespace ranges
8885

8986
# if _LIBCPP_STD_VER >= 23
9087
// [range.range]
91-
namespace ranges {
9288
template <class _Rp>
9389
using const_iterator_t = decltype(ranges::cbegin(std::declval<_Rp&>()));
94-
} // namespace ranges
9590
# endif // _LIBCPP_STD_VER >= 23
9691

9792
// [range.access.cend]
98-
namespace ranges {
93+
9994
namespace __cend {
10095
struct __fn {
10196
# if _LIBCPP_STD_VER >= 23
@@ -131,18 +126,14 @@ struct __fn {
131126
inline namespace __cpo {
132127
inline constexpr auto cend = __cend::__fn{};
133128
} // namespace __cpo
134-
} // namespace ranges
135129

136130
# if _LIBCPP_STD_VER >= 23
137131
// [range.range]
138-
namespace ranges {
139132
template <class _Rp>
140133
using const_sentinel_t = decltype(ranges::cend(std::declval<_Rp&>()));
141-
} // namespace ranges
142134
# endif
143135

144136
// [range.access.crbegin]
145-
namespace ranges {
146137
namespace __crbegin {
147138
struct __fn {
148139
# if _LIBCPP_STD_VER >= 23
@@ -178,10 +169,8 @@ struct __fn {
178169
inline namespace __cpo {
179170
inline constexpr auto crbegin = __crbegin::__fn{};
180171
} // namespace __cpo
181-
} // namespace ranges
182172

183173
// [range.access.crend]
184-
namespace ranges {
185174
namespace __crend {
186175
struct __fn {
187176
# if _LIBCPP_STD_VER >= 23
@@ -217,11 +206,9 @@ struct __fn {
217206
inline namespace __cpo {
218207
inline constexpr auto crend = __crend::__fn{};
219208
} // namespace __cpo
220-
} // namespace ranges
221209

222210
// [range.prim.cdata]
223211

224-
namespace ranges {
225212
namespace __cdata {
226213
struct __fn {
227214
# if _LIBCPP_STD_VER >= 23

libcxx/test/std/iterators/const.iterators/iterator.pass.cpp

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,23 @@ constexpr bool test_p2836r1() {
7373
return true;
7474
}
7575

76-
constexpr bool test_basic_operations() {
77-
struct S {
78-
int x;
79-
};
80-
S arr[10] = {};
81-
std::basic_const_iterator<S*> first = arr;
82-
std::basic_const_iterator<S*> last = arr + 10;
76+
struct S {
77+
int x;
78+
};
79+
80+
template <class It>
81+
constexpr void test_basic_operations() {
82+
S arr[10]{};
83+
84+
std::basic_const_iterator<It> first = It{arr};
85+
std::basic_const_iterator<It> last = It{arr + 10};
86+
87+
ASSERT_NOEXCEPT(first.base());
88+
assert(first.base() == It{arr});
89+
assert(last.base() == It{arr + 10});
90+
91+
static_assert(noexcept(iter_move(first)) == noexcept(std::ranges::iter_move(first.base())));
92+
static_assert(noexcept(std::ranges::iter_move(first)) == noexcept(std::ranges::iter_move(first.base())));
8393

8494
for (auto it = first; it != last; ++it) {
8595
(void)*it;
@@ -88,33 +98,46 @@ constexpr bool test_basic_operations() {
8898
}
8999
static_assert(!std::is_invocable_v<decltype(std::ranges::iter_swap), decltype(first), decltype(first)>);
90100

91-
assert(++first == arr + 1);
92-
assert(--first == arr + 0);
93-
assert(first++ == arr + 0);
94-
assert(first-- == arr + 1);
95-
96-
assert(first + 3 == arr + 3);
97-
assert(last - 1 == arr + 9);
98-
99-
first += 3;
100-
assert(first == arr + 3);
101-
first -= 2;
102-
assert(first == arr + 1);
103-
--first;
104-
105-
assert(first < last);
106-
assert(last > first);
107-
assert(first <= last);
108-
assert(last >= first);
109-
110-
assert(first < arr + 1);
111-
assert(arr + 1 > first);
112-
assert(first <= arr + 1);
113-
assert(arr + 1 >= first);
114-
115-
assert((first <=> last) < 0);
116-
assert((first <=> arr + 1) < 0);
117-
assert((arr + 1 <=> first) > 0);
101+
if constexpr (std::bidirectional_iterator<It>) {
102+
assert(++first == It{arr + 1});
103+
assert(--first == It{arr + 0});
104+
assert(first++ == It{arr + 0});
105+
assert(first-- == It{arr + 1});
106+
}
107+
108+
if constexpr (std::random_access_iterator<It>) {
109+
assert(first + 3 == It{arr + 3});
110+
assert(last - 1 == It{arr + 9});
111+
112+
first += 3;
113+
assert(first == It{arr + 3});
114+
first -= 2;
115+
assert(first == It{arr + 1});
116+
--first;
117+
118+
assert(first < last);
119+
assert(last > first);
120+
assert(first <= last);
121+
assert(last >= first);
122+
123+
assert(first < It{arr + 1});
124+
assert(It{arr + 1} > first);
125+
assert(first <= It{arr + 1});
126+
assert(It{arr + 1} >= first);
127+
128+
if constexpr (std::three_way_comparable<It>) {
129+
assert((first <=> last) < 0);
130+
assert((first <=> It{arr + 1}) < 0);
131+
assert((It{arr + 1} <=> first) > 0);
132+
}
133+
}
134+
}
135+
136+
constexpr bool test_basic_operations() {
137+
test_basic_operations<S*>();
138+
test_basic_operations<forward_iterator<S*>>();
139+
test_basic_operations<bidirectional_iterator<S*>>();
140+
test_basic_operations<random_access_iterator<S*>>();
118141

119142
return true;
120143
}

0 commit comments

Comments
 (0)