title: Using thrust::transform_reduce to transform an array (inclusive scan is not an answer)
body: <p>(Note <a href="https://stackoverflow.com/questions/33156534/pass-cuda-array-to-thrustinclusive-scan">this question</a> absolutely does not answer my question.)</p>
  <p>I would like to use <code>thrust::transform_reduce</code> to change the values of an array as well as perform a reduction. However, <code>transform_reduce</code> seems require that transform/reduce functions have pass-by-value semantics. Is there any way to access the values by address?</p>
  <p>The following MWE exemplifies the issue:</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;thrust/scan.h&gt;
  
  #include &lt;iostream&gt;
  
  int main(){
    const int N = 10;
  
    //Yes, I wish to use raw pointers rather than nice device vectors.
    int* data;
    if(cudaMalloc(&amp;data, N * sizeof(int))!=cudaSuccess){
      std::cout&lt;&lt;&quot;Couldn't allocate!&quot;&lt;&lt;std::endl;
      return -1;
    }
  
    const int answer = thrust::transform_reduce(
      data, data + N,
      [](auto x) -&gt; int32_t {
        //I would like to change the values of data here
        return 2;
      },
      int32_t{0},
      [](const int32_t running_sum, const int32_t this_value) -&gt; int32_t {
        return running_sum + this_value;
      }
    );
  
    if(answer!=20){
      std::cout&lt;&lt;&quot;Wrong answer!&quot;&lt;&lt;std::endl;
      return -1;
    }
  
    cudaFree(data); //In actuality, I'd do something with transformed data here
  
    return 0;
  }
  </code></pre>