counting_iterator#
-
template<class _Start, ::cuda::std::enable_if_t<::cuda::std::weakly_incrementable<_Start>, int> = 0, ::cuda::std::enable_if_t<::cuda::std::copyable<_Start>, int> = 0>
class counting_iterator : public __counting_iterator_category<_Start># A
counting_iterator
represents an iterator into a range of sequentially increasing values.This iterator is useful for creating a range filled with a sequence without explicitly storing it in memory. Using
counting_iterator
saves memory capacity and bandwidth.The following code snippet demonstrates how to create a
counting_iterator
whosevalue_type
isint
#include <cuda/iterator> ... // create iterators cuda::counting_iterator first(10); cuda::counting_iterator last = first + 3; first[0] // returns 10 first[1] // returns 11 first[100] // returns 110 // sum of [first, last) std::reduce(first, last); // returns 33 (i.e. 10 + 11 + 12) // initialize vector to [0,1,2,..] cuda::counting_iterator iter(0); std::vector<int> vec(500); std::copy(iter, iter + vec.size(), vec.begin());
- Template Parameters:
_Start – the value type of the
counting_iterator
.
Public Types
-
using iterator_concept = ::cuda::std::conditional_t<__advanceable<_Start>, ::cuda::std::random_access_iterator_tag, ::cuda::std::conditional_t<__decrementable<_Start>, ::cuda::std::bidirectional_iterator_tag, ::cuda::std::conditional_t<::cuda::std::incrementable<_Start>, ::cuda::std::forward_iterator_tag, ::cuda::std::input_iterator_tag>>>#
Public Functions
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<::cuda::std::default_initializable<_Start2>, int> = 0>
inline constexpr counting_iterator(
- inline explicit constexpr counting_iterator(
- _Start __value,
Creates a
counting_iterator
from an initial value.- Parameters:
__value – The value to store in the
counting_iterator
- inline constexpr _Start operator*(
Returns the value currently stored in the
counting_iterator
.
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<__advanceable<_Start2>, int> = 0>
inline constexpr _Start2 operator[]( - difference_type __n,
Returns the value currently stored in the
counting_iterator
advanced by a number of steps.- Parameters:
__n – The amount of elements to advance
- inline constexpr counting_iterator &operator++(
Increments the stored value.
- inline constexpr auto operator++(
- int,
Increments the stored value.
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<__decrementable<_Start2>, int> = 0>
inline constexpr counting_iterator &operator--( Decrements the stored value.
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<__decrementable<_Start2>, int> = 0>
inline constexpr counting_iterator operator--( - int,
Decrements the stored value.
- inline constexpr counting_iterator &operator+=(
- difference_type __n,
Increments the stored value by a given number of elements.
- Parameters:
__n – The number of elements to increment
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<__advanceable<_Start2>, int> = 0>
inline constexpr counting_iterator &operator-=( - difference_type __n,
Decrements the stored value by a given number of elements.
- Parameters:
__n – The amount of elements to decrement
Friends
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<__advanceable<_Start2>, int> = 0>
inline friend constexpr counting_iterator operator+( - counting_iterator __iter,
- difference_type __n,
Creates a copy of a
counting_iterator
advanced by a given number of elements.- Parameters:
__iter – The
counting_iterator
to advance__n – The amount of elements to advance
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<__advanceable<_Start2>, int> = 0>
inline friend constexpr counting_iterator operator+( - difference_type __n,
- counting_iterator __iter,
Creates a copy of a
counting_iterator
advanced by a given number of elements.- Parameters:
__iter – The
counting_iterator
to advance__n – The amount of elements to advance
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<__advanceable<_Start2>, int> = 0>
inline friend constexpr counting_iterator operator-( - counting_iterator __iter,
- difference_type __n,
Creates a copy of a
counting_iterator
decremented by a given number of elements.- Parameters:
__iter – The
counting_iterator
to decrement__n – The amount of elements to decrement
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<__advanceable<_Start2>, int> = 0>
inline friend constexpr difference_type operator-( - const counting_iterator &__x,
- const counting_iterator &__y,
Returns the distance between two
counting_iterator
.- Returns:
The difference between the stored values
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<::cuda::std::equality_comparable<_Start2>, int> = 0>
inline friend constexpr bool operator==( - const counting_iterator &__x,
- const counting_iterator &__y,
Compares two
counting_iterator
for equality.- Returns:
True if the stored values compare equal
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<::cuda::std::totally_ordered<_Start2>, int> = 0>
inline friend constexpr bool operator<( - const counting_iterator &__x,
- const counting_iterator &__y,
Compares two
counting_iterator
for less than.- Returns:
True if stored values compare less than
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<::cuda::std::totally_ordered<_Start2>, int> = 0>
inline friend constexpr bool operator>( - const counting_iterator &__x,
- const counting_iterator &__y,
Compares two
counting_iterator
for greater than.- Returns:
True if stored values compare greater than
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<::cuda::std::totally_ordered<_Start2>, int> = 0>
inline friend constexpr bool operator<=( - const counting_iterator &__x,
- const counting_iterator &__y,
Compares two
counting_iterator
for less equal.- Returns:
True if stored values compare less equal
-
template<class _Start2 = _Start, ::cuda::std::enable_if_t<::cuda::std::totally_ordered<_Start2>, int> = 0>
inline friend constexpr bool operator>=( - const counting_iterator &__x,
- const counting_iterator &__y,
Compares two
counting_iterator
for greater equal.- Returns:
True if stored values compare greater equal
-
template<class _Start>
inline constexpr auto make_counting_iterator( - _Start __start,
Creates a
counting_iterator
from an integer-like_Start
.- Parameters:
__start – The integer-like
_Start
representing the initial count