cub::ArgIndexInputIterator

Defined in cub/iterator/arg_index_input_iterator.cuh

template<typename InputIteratorT, typename OffsetT = ptrdiff_t, typename OutputValueT = cub::detail::value_t<InputIteratorT>>
class ArgIndexInputIterator

A random-access input wrapper for pairing dereferenced values with their corresponding indices (forming KeyValuePair tuples).

Overview

  • ArgIndexInputIterator wraps a random access input iterator itr of type InputIteratorT. Dereferencing an ArgIndexInputIterator at offset i produces a KeyValuePair value whose key field is i and whose value field is itr[i].

  • Can be used with any data type.

  • Can be constructed, manipulated, and exchanged within and between host and device functions. Wrapped host memory can only be dereferenced on the host, and wrapped device memory can only be dereferenced on the device.

  • Compatible with Thrust API v1.7 or newer.

Snippet

The code snippet below illustrates the use of ArgIndexInputIterator to dereference an array of doubles

#include <cub/cub.cuh>   // or equivalently <cub/iterator/arg_index_input_iterator.cuh>

// Declare, allocate, and initialize a device array
double *d_in;         // e.g., [8.0, 6.0, 7.0, 5.0, 3.0, 0.0, 9.0]

// Create an iterator wrapper
cub::ArgIndexInputIterator<double*> itr(d_in);

// Within device code:
cub::ArgIndexInputIterator<double*>::value_type tup = *itr;
printf("%f @ %ld\n",
  tup.value,
  tup.key);   // 8.0 @ 0

itr = itr + 6;
tup = *itr;
printf("%f @ %ld\n",
  tup.value,
  tup.key);   // 9.0 @ 6

Template Parameters
  • InputIteratorT – The value type of the wrapped input iterator

  • OffsetT – The difference type of this iterator (Default: ptrdiff_t)

  • OutputValueT – The paired value type of the <offset,value> tuple (Default: value type of input iterator)

Public Types

using self_type = ArgIndexInputIterator

My own type.

using difference_type = OffsetT

Type to express the result of subtracting one iterator from another.

using value_type = KeyValuePair<difference_type, OutputValueT>

The type of the element the iterator can point to.

using pointer = value_type*

The type of a pointer to an element the iterator can point to.

using reference = value_type

The type of a reference to an element the iterator can point to.

using iterator_category = typename THRUST_NS_QUALIFIER::detail::iterator_facade_category<THRUST_NS_QUALIFIER::any_system_tag, THRUST_NS_QUALIFIER::random_access_traversal_tag, value_type, reference>::type

The iterator category.

Public Functions

inline ArgIndexInputIterator(InputIteratorT itr, difference_type offset = 0)
Parameters
  • itr – Input iterator to wrap

  • offset – OffsetT (in items) from itr denoting the position of the iterator

inline self_type operator++(int)

Postfix increment.

inline self_type operator++()

Prefix increment.

inline reference operator*() const

Indirection.

template<typename Distance>
inline self_type operator+(Distance n) const

Addition.

template<typename Distance>
inline self_type &operator+=(Distance n)

Addition assignment.

template<typename Distance>
inline self_type operator-(Distance n) const

Subtraction.

template<typename Distance>
inline self_type &operator-=(Distance n)

Subtraction assignment.

inline difference_type operator-(self_type other) const

Distance.

template<typename Distance>
inline reference operator[](Distance n) const

Array subscript.

inline pointer operator->()

Structure dereference.

inline bool operator==(const self_type &rhs)

Equal to.

inline bool operator!=(const self_type &rhs)

Not equal to.

inline void normalize()

Normalize.

Friends

inline friend std::ostream &operator<<(std::ostream &os, const self_type&)

ostream operator