Skip to content

Commit 1fd78c6

Browse files
Test some properties of iterator operations
1 parent afbda54 commit 1fd78c6

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

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

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include <iterator>
1414
#include <list>
15+
#include <memory>
1516
#include <ranges>
1617
#include <vector>
1718
#include "test_macros.h"
@@ -95,12 +96,23 @@ constexpr void test_basic_operations() {
9596
(void)*it;
9697
(void)it->x;
9798
(void)iter_move(it);
99+
100+
std::same_as<decltype(it)> auto& it_ref = ++it;
101+
assert(std::addressof(it_ref) == std::addressof(it));
98102
}
99103
static_assert(!std::is_invocable_v<decltype(std::ranges::iter_swap), decltype(first), decltype(first)>);
100104

101105
if constexpr (std::bidirectional_iterator<It>) {
102-
assert(++first == It{arr + 1});
103-
assert(--first == It{arr + 0});
106+
{
107+
std::same_as<decltype(first)> auto& it_ref = ++first;
108+
assert(std::addressof(it_ref) == std::addressof(first));
109+
assert(it_ref == It{arr + 1});
110+
}
111+
{
112+
std::same_as<decltype(first)> auto& it_ref = --first;
113+
assert(std::addressof(it_ref) == std::addressof(first));
114+
assert(--first == It{arr + 0});
115+
}
104116
assert(first++ == It{arr + 0});
105117
assert(first-- == It{arr + 1});
106118
}
@@ -109,10 +121,16 @@ constexpr void test_basic_operations() {
109121
assert(first + 3 == It{arr + 3});
110122
assert(last - 1 == It{arr + 9});
111123

112-
first += 3;
113-
assert(first == It{arr + 3});
114-
first -= 2;
115-
assert(first == It{arr + 1});
124+
{
125+
std::same_as<decltype(first)> auto& it_ref = first += 3;
126+
assert(std::addressof(it_ref) == std::addressof(first));
127+
assert(first == It{arr + 3});
128+
}
129+
{
130+
std::same_as<decltype(first)> auto& it_ref = first -= 2;
131+
assert(std::addressof(it_ref) == std::addressof(first));
132+
assert(first == It{arr + 1});
133+
}
116134
--first;
117135

118136
assert(first < last);
@@ -135,6 +153,7 @@ constexpr void test_basic_operations() {
135153

136154
constexpr bool test_basic_operations() {
137155
test_basic_operations<S*>();
156+
test_basic_operations<cpp17_input_iterator<S*>>();
138157
test_basic_operations<forward_iterator<S*>>();
139158
test_basic_operations<bidirectional_iterator<S*>>();
140159
test_basic_operations<random_access_iterator<S*>>();

0 commit comments

Comments
 (0)