title: CUDA thrust remove_if with operlapping stencil sequence
body: <p>I was trying to remove elements from two <code>thrust::device_vector&lt;int&gt;</code> based on the values of the first vector. Intuitively I created the following snipped:</p>
  
  <pre><code>thrust::device_vector&lt;float&gt; idxToValue(COUNT_MAX);
  thrust::device_vector&lt;int&gt; idxSorted(COUNT_MAX);
  thrust::device_vector&lt;int&gt; groupIdxSorted(COUNT_MAX);
  int count = COUNT_MAX;
  float const minThreshold = MIN_THRESHOLD;
  
  auto idxToValueSortedIter = thrust::make_permutation_iterator(
      idxToValue.begin()
      , idxSorted.begin()
      );
  
  auto new_end = thrust::remove_if(
      thrust::make_zip_iterator(thrust::make_tuple(idxSorted.begin(), groupIdxSorted.begin()))
      , thrust::make_zip_iterator(thrust::make_tuple(idxSorted.begin() + count, groupIdxSorted.begin() + count))
      , idxToValueSortedIter 
      , thrust::placeholders::_1 &gt;= minThreshold
      );
  
  count = thrust::get&lt;0&gt;(new_end.get_iterator_tuple()) - idxSorted.begin();
  </code></pre>
  
  <p>The Thrust documentations unfortunately says </p>
  
  <blockquote>
    <p>The range [stencil, stencil + (last - first)) shall not overlap the range [result, result + (last - first))</p>
  </blockquote>
  
  <p>So in my case <code>idxToValueSortedIter</code>, which is used as stencil sequence, depends on <code>idxSorted</code> and is in fact overlapping the result (same vector).</p>
  
  <p>Is there any way to solve this without copying the data to a temporary vector?</p>