discard_iterator#
-
class discard_iterator#
discard_iterator
is an iterator which represents a special kind of pointer that ignores values written to it upon dereference.This iterator is useful for ignoring the output of certain algorithms without wasting memory capacity or bandwidth.
discard_iterator
may also be used to count the size of an algorithm’s output which may not be known a priori.The following code snippet demonstrates how to use
discard_iterator
to ignore one of the output ranges of reduce_by_key#include <cuda/iterator> #include <thrust/reduce.h> #include <thrust/device_vector.h> int main() { thrust::device_vector<int> keys{1, 3, 3, 3, 2, 2, 1}; thrust::device_vector<int> values{9, 8, 7, 6, 5, 4, 3}; thrust::device_vector<int> result(4); // we are only interested in the reduced values // use discard_iterator to ignore the output keys thrust::reduce_by_key(keys.begin(), keys.end(), values.begin(), cuda::discard_iterator{}, result.begin()); // result is now [9, 21, 9, 3] return 0; }
Public Types
-
using iterator_concept = ::cuda::std::random_access_iterator_tag#
-
using iterator_category = ::cuda::std::random_access_iterator_tag#
-
using difference_type = ::cuda::std::ptrdiff_t#
-
using value_type = void#
-
using pointer = void#
-
using reference = void#
Public Functions
-
constexpr discard_iterator() = default#
Default constructs a
discard_iterator
at index zero.
-
template<class _Integer, ::cuda::std::enable_if_t<::cuda::std::__integer_like<_Integer>, int> = 0>
inline constexpr discard_iterator( - _Integer __index,
Constructs a
discard_iterator
with a given index.- Parameters:
__index – The index used for the discard iterator
-
inline constexpr difference_type index() const noexcept#
Returns the stored index.
-
inline constexpr __discard_proxy operator*() const noexcept#
Dereferences the
discard_iterator
returning a proxy that discards all values that are assigned to it.
- inline constexpr __discard_proxy operator[]( ) const noexcept#
Subscipts the
discard_iterator
returning a proxy that discards all values that are assigned to it.
-
inline constexpr discard_iterator &operator++() noexcept#
Increments the stored index.
-
inline constexpr discard_iterator operator++(int) noexcept#
Increments the stored index.
-
inline constexpr discard_iterator &operator--() noexcept#
Decrements the stored index.
-
inline constexpr discard_iterator operator--(int) noexcept#
Decrements the stored index.
- inline constexpr discard_iterator operator+(
- difference_type __n,
Returns a copy of this
discard_iterator
advanced by a number of elements.- Parameters:
__n – The number of elements to advance
- inline constexpr discard_iterator &operator+=(
- difference_type __n,
Advances the index of this
discard_iterator
by a number of elements.- Parameters:
__n – The number of elements to advance
- inline constexpr discard_iterator operator-(
- difference_type __n,
Returns a copy of this
discard_iterator
decremented by a number of elements.- Parameters:
__n – The number of elements to decrement
- inline constexpr discard_iterator &operator-=(
- difference_type __n,
Decrements the index of the
discard_iterator
by a number of elements.- Parameters:
__n – The number of elements to decrement
Friends
- inline friend constexpr discard_iterator operator+(
- difference_type __n,
- const discard_iterator &__x,
Returns a copy of a
discard_iterator
advanced by a number of elements.- Parameters:
__n – The number of elements to advance
__x – The original
discard_iterator
- inline friend constexpr difference_type operator-(
- const discard_iterator &__lhs,
- const discard_iterator &__rhs,
Returns the distance between two
discard_iterator's
.- Parameters:
__lhs – The left
discard_iterator
__rhs – The right
discard_iterator
- Returns:
__rhs.__index_ - __lhs.__index_
- inline friend constexpr difference_type operator-(
- const discard_iterator &__lhs,
- ::cuda::std::default_sentinel_t,
Returns the distance between a
default_sentinel
and adiscard_iterator
.- Parameters:
__lhs – The
discard_iterator
- Returns:
-__lhs.__index_
- inline friend constexpr difference_type operator-(
- ::cuda::std::default_sentinel_t,
- const discard_iterator &__rhs,
Returns the distance between a
discard_iterator
and adefault_sentinel
.- Parameters:
__rhs – The
discard_iterator
- Returns:
__rhs.__index_
- inline friend constexpr bool operator==(
- const discard_iterator &__lhs,
- const discard_iterator &__rhs,
Compares two
discard_iterator
for equality by comparing the indices.
- inline friend constexpr bool operator==(
- const discard_iterator &__lhs,
- ::cuda::std::default_sentinel_t,
Compares a
discard_iterator
withdefault_sentinel
.- Parameters:
__lhs – is zero
- Returns:
True if the index of
- inline friend constexpr bool operator<(
- const discard_iterator &__lhs,
- const discard_iterator &__rhs,
Compares two
discard_iterator
for less than by comparing the indices.
- inline friend constexpr bool operator<=(
- const discard_iterator &__lhs,
- const discard_iterator &__rhs,
Compares two
discard_iterator
for less equal by comparing the indices.
- inline friend constexpr bool operator>(
- const discard_iterator &__lhs,
- const discard_iterator &__rhs,
Compares two
discard_iterator
for greater than by comparing the indices.
- inline friend constexpr bool operator>=(
- const discard_iterator &__lhs,
- const discard_iterator &__rhs,
Compares two
discard_iterator
for greater equal by comparing the indices.
-
template<class _Integer = ::cuda::std::ptrdiff_t, ::cuda::std::enable_if_t<::cuda::std::__integer_like<_Integer>, int> = 0>
inline constexpr discard_iterator make_discard_iterator( - _Integer __index = 0,
Creates a
discard_iterator
from an optional index.- Parameters:
__index – The index of the
discard_iterator
within a range. The default index is0
.- Returns:
A new
discard_iterator
with__index
as the counter.
-
using iterator_concept = ::cuda::std::random_access_iterator_tag#