Skip to content

Commit 8e2db4e

Browse files
committed
Allow iterators to be decremented past begin and incremented past end
1 parent 91f0d30 commit 8e2db4e

File tree

2 files changed

+4
-47
lines changed

2 files changed

+4
-47
lines changed

sycl/include/sycl/detail/accessor_iterator.hpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ template <typename _DataT, int _Dimensions> class __accessor_iterator {
6060
}
6161

6262
__accessor_iterator &operator++() {
63-
if (_MLinearId < _MEnd)
64-
++_MLinearId;
63+
++_MLinearId;
6564
return *this;
6665
}
6766

@@ -72,8 +71,7 @@ template <typename _DataT, int _Dimensions> class __accessor_iterator {
7271
}
7372

7473
__accessor_iterator &operator--() {
75-
if (_MLinearId > _MBegin)
76-
--_MLinearId;
74+
--_MLinearId;
7775
return *this;
7876
}
7977

@@ -84,15 +82,7 @@ template <typename _DataT, int _Dimensions> class __accessor_iterator {
8482
}
8583

8684
__accessor_iterator &operator+=(difference_type _N) {
87-
if (_N < 0) {
88-
*this -= -_N;
89-
return *this;
90-
}
91-
92-
if (static_cast<size_t>(_N) > _MEnd || _MEnd - _N < _MLinearId)
93-
_MLinearId = _MEnd;
94-
else
95-
_MLinearId += _N;
85+
_MLinearId += _N;
9686

9787
return *this;
9888
}
@@ -112,15 +102,7 @@ template <typename _DataT, int _Dimensions> class __accessor_iterator {
112102
}
113103

114104
__accessor_iterator &operator-=(difference_type _N) {
115-
if (_N < 0) {
116-
*this += -_N;
117-
return *this;
118-
}
119-
120-
if (_MBegin + _N > _MLinearId)
121-
_MLinearId = _MBegin;
122-
else
123-
_MLinearId -= _N;
105+
_MLinearId -= _N;
124106

125107
return *this;
126108
}

sycl/unittests/accessor/AccessorIterator.cpp

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -116,31 +116,6 @@ class AccessorIteratorTest : public ::testing::Test {
116116
}
117117
};
118118

119-
TEST_F(AccessorIteratorTest, ImplementationDetails) {
120-
std::vector<int> reference(5);
121-
std::iota(reference.begin(), reference.end(), 0);
122-
sycl::buffer<int> buffer(reference.data(), sycl::range<1>{reference.size()});
123-
auto accessor = buffer.template get_access<sycl::access_mode::read_write>();
124-
{
125-
auto It = accessor.begin();
126-
// Check that It can't be decremented past begin
127-
ASSERT_EQ(--It, accessor.begin());
128-
ASSERT_EQ(It - 1, accessor.begin());
129-
ASSERT_EQ(It -= 1, accessor.begin());
130-
ASSERT_EQ(It - 10, accessor.begin());
131-
ASSERT_EQ(It -= 10, accessor.begin());
132-
}
133-
{
134-
auto It = accessor.end();
135-
// Check that It can't be incremented past end
136-
ASSERT_EQ(++It, accessor.end());
137-
ASSERT_EQ(It + 1, accessor.end());
138-
ASSERT_EQ(It += 1, accessor.end());
139-
ASSERT_EQ(It + 10, accessor.end());
140-
ASSERT_EQ(It += 10, accessor.end());
141-
}
142-
}
143-
144119
// FIXME: consider turning this into parameterized test to check various
145120
// accessor types
146121
TEST_F(AccessorIteratorTest, IteratorTraits) {

0 commit comments

Comments
 (0)