title: how to avoid copying in boost range transform
body: <p>boost range transform requires <code>const &amp;</code> for ranges in arguments.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;boost/range/algorithm.hpp&gt;
  
  int main(int argc, char *argv[])
  {
    using namespace std;
  
    vector&lt;vector&lt;int&gt;&gt; rt0(10,vector&lt;int&gt;(15,2));
    vector&lt;vector&lt;int&gt;&gt; irt(10,vector&lt;int&gt;(15,5));
  
    for(auto &amp; i:rt0) {
      for(auto&amp; j:i) cout &lt;&lt; j &lt;&lt; "  ";
      cout &lt;&lt; "\n";
    }
    cout &lt;&lt; "\n";
    for(auto &amp; i:irt) {
      for(auto&amp; j:i) cout &lt;&lt; j &lt;&lt; "  ";
      cout &lt;&lt; "\n";
    }
  
    boost::transform(rt0,irt,rt0.begin(),
      [] (const vector&lt;int&gt; &amp;t0,const vector&lt;int&gt; &amp;it) {
        auto tt = t0;
        boost::transform(t0,it,tt.begin(), plus&lt;int&gt;());
        return tt;
      }
    );
    cout &lt;&lt; "\n";
    cout &lt;&lt; "\n";
    for(auto &amp; i:rt0) {
      for(auto&amp; j:i) cout &lt;&lt; j &lt;&lt; "  ";
      cout &lt;&lt; "\n";
    }
    return 0;
  }
  </code></pre>
  
  <p>compile and run with</p>
  
  <pre><code>g++ -std=c++11 main.cc; ./a.out
  </code></pre>
  
  <p>if <code>boost::transform</code>'s <code>BinaryOperation</code> took <code>&amp;</code> instead of <code>const &amp;</code> for <code>SinglePassRange1</code> then i wouldn't have needed to create a copy (<code>auto tt = t0</code>) and just use <code>to</code> instead of <code>tt</code>. is there a way to avoid creating this copying (while still using ranges)?</p>
  
  <p>link to boost range transform: <a href="http://www.boost.org/doc/libs/1_53_0/libs/range/doc/html/range/reference/algorithms/mutating/transform.html" rel="nofollow">http://www.boost.org/doc/libs/1_53_0/libs/range/doc/html/range/reference/algorithms/mutating/transform.html</a></p>