thrust::permutation_iterator
Defined in thrust/iterator/permutation_iterator.h
- 
template<typename ElementIterator, typename IndexIterator>
 class permutation_iterator
- permutation_iteratoris an iterator which represents a pointer into a reordered view of a given range.- permutation_iteratoris an imprecise name; the reordered view need not be a strict permutation. This iterator is useful for fusing a scatter or gather operation with other algorithms.- This iterator takes two arguments: - an iterator to the range - Von which the “permutation” will be applied
- the reindexing scheme that defines how the elements of - Vwill be permuted.
 - Note that - permutation_iteratoris not limited to strict permutations of the given range- V. The distance between begin and end of the reindexing iterators is allowed to be smaller compared to the size of the range- V, in which case the- permutation_iteratoronly provides a “permutation” of a subrange of- V. The indices neither need to be unique. In this same context, it must be noted that the past-the-end- permutation_iteratoris completely defined by means of the past-the-end iterator to the indices.- The following code snippet demonstrates how to create a - permutation_iteratorwhich represents a reordering of the contents of a- device_vector.- #include <thrust/iterator/permutation_iterator.h> #include <thrust/device_vector.h> ... thrust::device_vector<float> values(8); values[0] = 10.0f; values[1] = 20.0f; values[2] = 30.0f; values[3] = 40.0f; values[4] = 50.0f; values[5] = 60.0f; values[6] = 70.0f; values[7] = 80.0f; thrust::device_vector<int> indices(4); indices[0] = 2; indices[1] = 6; indices[2] = 1; indices[3] = 3; using ElementIterator = thrust::device_vector<float>::iterator; using IndexIterator = thrust::device_vector<int>::iterator ; thrust::permutation_iterator<ElementIterator,IndexIterator> iter(values.begin(), indices.begin()); *iter; // returns 30.0f; iter[0]; // returns 30.0f; iter[1]; // returns 70.0f; iter[2]; // returns 20.0f; iter[3]; // returns 40.0f; // iter[4] is an out-of-bounds error *iter = -1.0f; // sets values[2] to -1.0f; iter[0] = -1.0f; // sets values[2] to -1.0f; iter[1] = -1.0f; // sets values[6] to -1.0f; iter[2] = -1.0f; // sets values[1] to -1.0f; iter[3] = -1.0f; // sets values[3] to -1.0f; // values is now {10, -1, -1, -1, 50, 60, -1, 80} - See also - make_permutation_iterator - Public Functions - 
permutation_iterator() = default
- Null constructor calls the null constructor of this - permutation_iterator'selement iterator.
 - 
inline explicit permutation_iterator(ElementIterator x, IndexIterator y)
- Constructor accepts an - ElementIteratorinto a range of values and an- IndexIteratorinto a range of indices defining the indexing scheme on the values.- Parameters
- x – An - ElementIteratorpointing this- permutation_iterator'srange of values.
- y – An - IndexIteratorpointing to an indexing scheme to use on- x.
 
 
 - 
template<typename OtherElementIterator, typename OtherIndexIterator, detail::enable_if_convertible_t<OtherElementIterator, ElementIterator, int> = 0, detail::enable_if_convertible_t<OtherIndexIterator, IndexIterator, int> = 0>
 inline permutation_iterator(permutation_iterator<OtherElementIterator, OtherIndexIterator> const &rhs)
- Copy constructor accepts a related - permutation_iterator.- Parameters
- r – A compatible - permutation_iteratorto copy from.