title: C++: What is the correct cast for offseting to std::vector iterator?
body: <p>I have a function that takes a <code>std::vector</code> of doubles, and copies them to another vector, but at a particular offset (assume there is sufficient space):</p>
  
  <pre><code>void copy_stuff(const std::vector&lt;double&gt; &amp; data,
                  std::vector&lt;double&gt; &amp; dest,
                  size_t dest_offset) {
      std::copy(data.begin(), data.end(), dest.begin() + dest_offset);
  }
  </code></pre>
  
  <p>This results in a C++11 clang compiler <code>-Weverything</code> warning centered on the <code>+ dest_offset</code> part:</p>
  
  <blockquote>
    <p>Implicit conversion changes signedness: 'size_t' (aka 'unsigned long') to 'difference_type' (aka 'long').</p>
  </blockquote>
  
  <p>I'm not sure how I should cast the expression <code>dest.begin() + dest_offset</code> in order to eliminate this warning. Casting the result to a <code>double *</code> does not compile:</p>
  
  <pre><code>    std::copy(data, data + data_size, static_cast&lt;double *&gt;(dest.begin() + dest_offset));
  </code></pre>
  
  <blockquote>
    <p>Cannot cast from type 'std::__1::__wrap_iter' to pointer type 'double *'.</p>
  </blockquote>
  
  <p>I had considered using vector indexing and then taking the address:</p>
  
  <pre><code>    std::copy(data, data + data_size, &amp;dest[dest_offset]);
  </code></pre>
  
  <p>This seems to eliminate the warning in this case, but doesn't compile if I try to use the same pattern with the source vector, i.e. with an offset involved with the first or second parameter of <code>std::copy</code>. For example:</p>
  
  <pre><code>static void copy_stuff_differently(const std::vector&lt;double&gt; &amp; data,
                                     std::vector&lt;double&gt; &amp; dest,
                                     size_t offset) {
      std::copy(data.begin() + offset, data.end(), dest.begin());
  }
  </code></pre>
  
  <p>Gives the same original warning of implicit conversion on the <code>+ offset</code>. Attempting to use the address-of-index might suggest:</p>
  
  <pre><code>    std::copy(&amp;data[offset], data.end(), dest.begin());
  </code></pre>
  
  <p>Or a different but similar case:</p>
  
  <pre><code>    std::copy(data.begin(), &amp;data[offset], dest.begin());
  </code></pre>
  
  <p>However both cause a similar error:</p>
  
  <pre><code>test.cpp:8:3: error: no matching function for call to 'copy'
    std::copy(&amp;data[offset], data.end(), dest.begin());
    ^~~~~~~~~
   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iterator:1286:48: note:
        candidate template ignored: deduced conflicting types for parameter '_Ip' ('const double *' vs.
        'std::__1::__wrap_iter&lt;const double *&gt;')
      template &lt;class _Ip, class _Op&gt; friend _Op copy(_Ip, _Ip, _Op);
                                                 ^
  </code></pre>
  
  <p>I'm looking for a consistent and warning-free way to handle such offsets. What is the right way to handle offsets into a vector and avoid such errors and warnings?</p>