Skip to content

Commit 2ffbcad

Browse files
committed
Address review feedback
1 parent da875d5 commit 2ffbcad

File tree

7 files changed

+134
-150
lines changed

7 files changed

+134
-150
lines changed

libcudacxx/include/cuda/__iterator/discard_iterator.h

Lines changed: 59 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,16 @@ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
4747
//!
4848
//! int main()
4949
//! {
50-
//! thrust::device_vector<int> keys(7), values(7);
51-
//!
52-
//! keys[0] = 1;
53-
//! keys[1] = 3;
54-
//! keys[2] = 3;
55-
//! keys[3] = 3;
56-
//! keys[4] = 2;
57-
//! keys[5] = 2;
58-
//! keys[6] = 1;
59-
//!
60-
//! values[0] = 9;
61-
//! values[1] = 8;
62-
//! values[2] = 7;
63-
//! values[3] = 6;
64-
//! values[4] = 5;
65-
//! values[5] = 4;
66-
//! values[6] = 3;
50+
//! thrust::device_vector<int> keys{1, 3, 3, 3, 2, 2, 1};
51+
//! thrust::device_vector<int> values{9, 8, 7, 6, 5, 4, 3};
6752
//!
6853
//! thrust::device_vector<int> result(4);
6954
//!
7055
//! // we are only interested in the reduced values
7156
//! // use discard_iterator to ignore the output keys
7257
//! thrust::reduce_by_key(keys.begin(), keys.end(),
7358
//! values.begin(),
74-
//! cuda::make_discard_iterator(),
59+
//! cuda::discard_iterator{},
7560
//! result.begin());
7661
//!
7762
//! // result is now [9, 21, 9, 3]
@@ -82,7 +67,7 @@ _LIBCUDACXX_BEGIN_NAMESPACE_CUDA
8267
class discard_iterator
8368
{
8469
private:
85-
_CUDA_VSTD::ptrdiff_t __counter_ = 0;
70+
_CUDA_VSTD::ptrdiff_t __index_ = 0;
8671

8772
struct __discard_proxy
8873
{
@@ -102,21 +87,21 @@ class discard_iterator
10287
using pointer = void*;
10388
using reference = void;
10489

105-
//! @brief Default constructs a \p discard_iterator with a value initialized counter
90+
//! @brief Default constructs a \p discard_iterator at index zero
10691
_CCCL_HIDE_FROM_ABI constexpr discard_iterator() = default;
10792

108-
//! @brief Constructs a \p discard_iterator with a given \p __counter
109-
//! @param __counter The counter used for the discard iterator
93+
//! @brief Constructs a \p discard_iterator with a given \p __index
94+
//! @param __index The index used for the discard iterator
11095
_CCCL_TEMPLATE(class _Integer)
11196
_CCCL_REQUIRES(_CUDA_VSTD::__integer_like<_Integer>)
112-
_LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator(_Integer __counter) noexcept
113-
: __counter_(static_cast<_CUDA_VSTD::ptrdiff_t>(__counter))
97+
_LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator(_Integer __index) noexcept
98+
: __index_(static_cast<_CUDA_VSTD::ptrdiff_t>(__index))
11499
{}
115100

116-
//! @brief Returns the stored counter
117-
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI constexpr difference_type count() const noexcept
101+
//! @brief Returns the stored index
102+
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI constexpr difference_type index() const noexcept
118103
{
119-
return __counter_;
104+
return __index_;
120105
}
121106

122107
//! @brief Dereferences the \c discard_iterator returning a proxy that discards all values that are assigned to it
@@ -131,41 +116,41 @@ class discard_iterator
131116
return {};
132117
}
133118

134-
//! @brief Increments the stored counter
119+
//! @brief Increments the stored index
135120
_LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator& operator++() noexcept
136121
{
137-
++__counter_;
122+
++__index_;
138123
return *this;
139124
}
140125

141-
//! @brief Increments the stored counter
126+
//! @brief Increments the stored index
142127
_LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator operator++(int) noexcept
143128
{
144129
discard_iterator __tmp = *this;
145-
++__counter_;
130+
++__index_;
146131
return __tmp;
147132
}
148133

149-
//! @brief Decrements the stored counter
134+
//! @brief Decrements the stored index
150135
_LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator& operator--() noexcept
151136
{
152-
--__counter_;
137+
--__index_;
153138
return *this;
154139
}
155140

156-
//! @brief Decrements the stored counter
141+
//! @brief Decrements the stored index
157142
_LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator operator--(int) noexcept
158143
{
159144
discard_iterator __tmp = *this;
160-
--__counter_;
145+
--__index_;
161146
return __tmp;
162147
}
163148

164149
//! @brief Returns a copy of this \c discard_iterator advanced by \p __n
165150
//! @param __n The number of elements to advance
166151
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator operator+(difference_type __n) const noexcept
167152
{
168-
return discard_iterator{__counter_ + __n};
153+
return discard_iterator{__index_ + __n};
169154
}
170155

171156
//! @brief Returns a copy of \p __x advanced by \p __n
@@ -177,179 +162,178 @@ class discard_iterator
177162
return __x + __n;
178163
}
179164

180-
//! @brief Advances this \c discard_iterator by \p __n
165+
//! @brief Advances the index of this \c discard_iterator by \p __n
181166
//! @param __n The number of elements to advance
182167
_LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator& operator+=(difference_type __n) noexcept
183168
{
184-
__counter_ += __n;
169+
__index_ += __n;
185170
return *this;
186171
}
187172

188173
//! @brief Returns a copy of this \c discard_iterator decremented by \p __n
189174
//! @param __n The number of elements to decrement
190175
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator operator-(difference_type __n) const noexcept
191176
{
192-
return discard_iterator{__counter_ - __n};
177+
return discard_iterator{__index_ - __n};
193178
}
194179

195180
//! @brief Returns the distance between \p __lhs and \p __rhs
196181
//! @param __lhs The left \c discard_iterator
197182
//! @param __rhs The right \c discard_iterator
198-
//! @return __rhs.__counter_ - __lhs.__counter_
183+
//! @return __rhs.__index_ - __lhs.__index_
199184
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr difference_type
200185
operator-(const discard_iterator& __lhs, const discard_iterator& __rhs) noexcept
201186
{
202-
return __rhs.__counter_ - __lhs.__counter_;
187+
return __rhs.__index_ - __lhs.__index_;
203188
}
204189

205190
//! @brief Returns the distance between \p __lhs a \p default_sentinel
206191
//! @param __lhs The left \c discard_iterator
207-
//! @return -__lhs.__counter_
192+
//! @return -__lhs.__index_
208193
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr difference_type
209194
operator-(const discard_iterator& __lhs, _CUDA_VSTD::default_sentinel_t) noexcept
210195
{
211-
return static_cast<difference_type>(-__lhs.__counter_);
196+
return static_cast<difference_type>(-__lhs.__index_);
212197
}
213198

214199
//! @brief Returns the distance between a \p default_sentinel and \p __rhs
215200
//! @param __rhs The right \c discard_iterator
216-
//! @return __rhs.__coutner_
201+
//! @return __rhs.__index_
217202
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr difference_type
218203
operator-(_CUDA_VSTD::default_sentinel_t, const discard_iterator& __rhs) noexcept
219204
{
220-
return static_cast<difference_type>(__rhs.__counter_);
205+
return static_cast<difference_type>(__rhs.__index_);
221206
}
222207

223-
//! @brief Decrements the \c discard_iterator by \p __n
208+
//! @brief Decrements the index of the \c discard_iterator by \p __n
224209
//! @param __n The number of elements to decrement
225210
_LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator& operator-=(difference_type __n) noexcept
226211
{
227-
__counter_ -= __n;
212+
__index_ -= __n;
228213
return *this;
229214
}
230215

231216
//! @brief Compares two \c discard_iterator \p __lhs and \p __rhs for equality
232217
//! @param __lhs The left \c discard_iterator
233218
//! @param __rhs The right \c discard_iterator
234-
//! @return true if both iterators store the same counter
219+
//! @return true if both iterators store the same index
235220
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool
236221
operator==(const discard_iterator& __lhs, const discard_iterator& __rhs) noexcept
237222
{
238-
return __lhs.__counter_ == __rhs.__counter_;
223+
return __lhs.__index_ == __rhs.__index_;
239224
}
240225

241226
#if _CCCL_STD_VER <= 2017
242227
//! @brief Compares two \c discard_iterator \p __lhs and \p __rhs for inequality
243228
//! @param __lhs The left \c discard_iterator
244229
//! @param __rhs The right \c discard_iterator
245-
//! @return true if both iterators store different counters
230+
//! @return true if both iterators store different indexs
246231
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool
247232
operator!=(const discard_iterator& __lhs, const discard_iterator& __rhs) noexcept
248233
{
249-
return __lhs.__counter_ != __rhs.__counter_;
234+
return __lhs.__index_ != __rhs.__index_;
250235
}
251236
#endif // _CCCL_STD_VER <= 2017
252237

253238
//! @brief Compares a \c discard_iterator \p __lhs with \p default_sentinel for equality
254239
//! @param __lhs The left \c discard_iterator
255-
//! @return true if the counter of \p __lhs is zero
240+
//! @return true if the index of \p __lhs is zero
256241
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool
257242
operator==(const discard_iterator& __lhs, _CUDA_VSTD::default_sentinel_t) noexcept
258243
{
259-
return __lhs.__counter_ == 0;
244+
return __lhs.__index_ == 0;
260245
}
261246

262247
#if _CCCL_STD_VER <= 2017
263248
//! @brief Compares a \c discard_iterator \p __rhs with \p default_sentinel for equality
264249
//! @param __rhs The right \c discard_iterator
265-
//! @return true if the counter of \p __rhs is zero
250+
//! @return true if the index of \p __rhs is zero
266251
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool
267252
operator==(_CUDA_VSTD::default_sentinel_t, const discard_iterator& __rhs) noexcept
268253
{
269-
return __rhs.__counter_ == 0;
254+
return __rhs.__index_ == 0;
270255
}
271256

272257
//! @brief Compares a \c discard_iterator \p __rhs with \p default_sentinel for inequality
273258
//! @param __lhs The right \c discard_iterator
274-
//! @return true if the counter of \p __lhs is not zero
259+
//! @return true if the index of \p __lhs is not zero
275260
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool
276261
operator!=(const discard_iterator& __lhs, _CUDA_VSTD::default_sentinel_t) noexcept
277262
{
278-
return __lhs.__counter_ != 0;
263+
return __lhs.__index_ != 0;
279264
}
280265

281266
//! @brief Compares a \c discard_iterator \p __rhs with \p default_sentinel for inequality
282267
//! @param __rhs The right \c discard_iterator
283-
//! @return true if the counter of \p __rhs is not zero
268+
//! @return true if the index of \p __rhs is not zero
284269
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool
285270
operator!=(_CUDA_VSTD::default_sentinel_t, const discard_iterator& __rhs) noexcept
286271
{
287-
return __rhs.__counter_ != 0;
272+
return __rhs.__index_ != 0;
288273
}
289274
#endif // _CCCL_STD_VER <= 2017
290275

291276
#if _LIBCUDACXX_HAS_SPACESHIP_OPERATOR()
292277
//! @brief Three-way-compares two \c discard_iterator \p __lhs and \p __rhs
293278
//! @param __lhs The left \c discard_iterator
294279
//! @param __rhs The right \c discard_iterator
295-
//! @return the three-way ordering of the counters stored by \p __lhs and \p __rhs
280+
//! @return the three-way ordering of the indexs stored by \p __lhs and \p __rhs
296281
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr strong_ordering
297282
operator<=>(const discard_iterator& __lhs, const discard_iterator& __rhs) noexcept
298283
{
299-
return __lhs.__counter_ <=> __rhs.__counter_;
284+
return __lhs.__index_ <=> __rhs.__index_;
300285
}
301286
#endif // _LIBCUDACXX_HAS_SPACESHIP_OPERATOR()
302287

303288
//! @brief Compares two \c discard_iterator \p __lhs and \p __rhs for less than
304289
//! @param __lhs The left \c discard_iterator
305290
//! @param __rhs The right \c discard_iterator
306-
//! @return true if the counter stored by \p __lhs compares less than the one stored by \p __rhs
291+
//! @return true if the index stored by \p __lhs compares less than the one stored by \p __rhs
307292
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool
308293
operator<(const discard_iterator& __lhs, const discard_iterator& __rhs) noexcept
309294
{
310-
return __lhs.__counter_ < __rhs.__counter_;
295+
return __lhs.__index_ < __rhs.__index_;
311296
}
312297

313298
//! @brief Compares two \c discard_iterator \p __lhs and \p __rhs for less equal
314299
//! @param __lhs The left \c discard_iterator
315300
//! @param __rhs The right \c discard_iterator
316-
//! @return true if the counter stored by \p __lhs compares less equal the one stored by \p __rhs
301+
//! @return true if the index stored by \p __lhs compares less equal the one stored by \p __rhs
317302
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool
318303
operator<=(const discard_iterator& __lhs, const discard_iterator& __rhs) noexcept
319304
{
320-
return __lhs.__counter_ <= __rhs.__counter_;
305+
return __lhs.__index_ <= __rhs.__index_;
321306
}
322307

323308
//! @brief Compares two \c discard_iterator \p __lhs and \p __rhs for greater than
324309
//! @param __lhs The left \c discard_iterator
325310
//! @param __rhs The right \c discard_iterator
326-
//! @return true if the counter stored by \p __lhs compares less greater the one stored by \p __rhs
311+
//! @return true if the index stored by \p __lhs compares less greater the one stored by \p __rhs
327312
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool
328313
operator>(const discard_iterator& __lhs, const discard_iterator& __rhs) noexcept
329314
{
330-
return __lhs.__counter_ > __rhs.__counter_;
315+
return __lhs.__index_ > __rhs.__index_;
331316
}
332317

333318
//! @brief Compares two \c discard_iterator \p __lhs and \p __rhs for greater equal
334319
//! @param __lhs The left \c discard_iterator
335320
//! @param __rhs The right \c discard_iterator
336-
//! @return true if the counter stored by \p __lhs compares greater equal the one stored by \p __rhs
321+
//! @return true if the index stored by \p __lhs compares greater equal the one stored by \p __rhs
337322
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI friend constexpr bool
338323
operator>=(const discard_iterator& __lhs, const discard_iterator& __rhs) noexcept
339324
{
340-
return __lhs.__counter_ >= __rhs.__counter_;
325+
return __lhs.__index_ >= __rhs.__index_;
341326
}
342327
};
343328

344-
//! @brief Creates a \p discard_iterator from an optional counter.
345-
//! @param __counter The index of the returned \p discard_iterator within a range. In the default case, the value of
346-
//! this parameter is \c 0.
347-
//! @return A new \p discard_iterator with \p __counter as the couner.
329+
//! @brief Creates a \p discard_iterator from an optional index.
330+
//! @param __index The index of the \p discard_iterator within a range. The default index is \c 0.
331+
//! @return A new \p discard_iterator with \p __index as the couner.
348332
_CCCL_TEMPLATE(class _Integer = _CUDA_VSTD::ptrdiff_t)
349333
_CCCL_REQUIRES(_CUDA_VSTD::__integer_like<_Integer>)
350-
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator make_discard_iterator(_Integer __counter = 0)
334+
[[nodiscard]] _LIBCUDACXX_HIDE_FROM_ABI constexpr discard_iterator make_discard_iterator(_Integer __index = 0)
351335
{
352-
return discard_iterator{__counter};
336+
return discard_iterator{__index};
353337
}
354338

355339
_LIBCUDACXX_END_NAMESPACE_CUDA

libcudacxx/test/libcudacxx/cuda/iterators/discard_iterator/decrement.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717

1818
__host__ __device__ constexpr bool test()
1919
{
20-
const int counter = 3;
21-
cuda::discard_iterator iter(counter);
22-
assert(iter-- == cuda::discard_iterator(counter + 0));
23-
assert(--iter == cuda::discard_iterator(counter - 2));
20+
const int index = 3;
21+
cuda::discard_iterator iter(index);
22+
assert(iter-- == cuda::discard_iterator(index + 0));
23+
assert(--iter == cuda::discard_iterator(index - 2));
2424

2525
static_assert(cuda::std::is_same_v<decltype(iter--), cuda::discard_iterator>);
2626
static_assert(cuda::std::is_same_v<decltype(--iter), cuda::discard_iterator&>);

libcudacxx/test/libcudacxx/cuda/iterators/discard_iterator/deref.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
__host__ __device__ constexpr bool test()
2020
{
2121
{
22-
const int counter = 2;
23-
cuda::discard_iterator iter(counter);
22+
const int index = 2;
23+
cuda::discard_iterator iter(index);
2424
*iter = 42;
2525
}
2626

2727
{
28-
const int counter = 2;
29-
const cuda::discard_iterator iter(counter);
28+
const int index = 2;
29+
const cuda::discard_iterator iter(index);
3030
*iter = 42;
3131
}
3232

libcudacxx/test/libcudacxx/cuda/iterators/discard_iterator/increment.pass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
__host__ __device__ constexpr bool test()
1919
{
20-
const int counter = 2;
21-
cuda::discard_iterator iter(counter);
20+
const int index = 2;
21+
cuda::discard_iterator iter(index);
2222

23-
assert(iter++ == cuda::discard_iterator(counter + 0));
24-
assert(++iter == cuda::discard_iterator(counter + 2));
23+
assert(iter++ == cuda::discard_iterator(index + 0));
24+
assert(++iter == cuda::discard_iterator(index + 2));
2525

2626
static_assert(cuda::std::is_same_v<decltype(iter++), cuda::discard_iterator>);
2727
static_assert(cuda::std::is_same_v<decltype(++iter), cuda::discard_iterator&>);

0 commit comments

Comments
 (0)