title: What is the benefit of using std::copy instead of manual for loop to copy dynamic array?
body: <p>Suppose I have the following code: </p>
  
  <pre><code>int* intPtr = new int[5];
  
  // ...do stuff...
  </code></pre>
  
  <p><br>
  And now I want to copy intPtr to a new, identical, array:</p>
  
  <pre><code>int* newIntPtr = new int[5];
  </code></pre>
  
  <p><br>
  This can be done using either a simple for-loop or std::copy():</p>
  
  <ol>
  <li><p>Using a for loop</p>
  
  <pre><code>for (int i = 0; i &lt; 5; i++)
      *(newIntPtr + i) = *(intPtr + i);
  </code></pre></li>
  <li><p>Using std::copy()</p>
  
  <pre><code>std::copy( intPtr, intPtr + 5, newIntPtr );
  </code></pre></li>
  </ol>
  
  <p><br>
  Using std::copy(), I get a warning in Visual Studio:</p>
  
  <pre><code>warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe...
  </code></pre>
  
  <p><br>
  I <strong>could</strong> use <code>stdext::checked_array_iterator&lt;int*&gt;</code> to make the warning go away:</p>
  
  <pre><code>std::copy(intPtr, intPtr + 5, stdext::checked_array_iterator&lt;int*&gt;(newIntPtr, 5));
  </code></pre>
  
  <p>but that means the code won't compile on anything else than Visual Studio.</p>
  
  <p>So, how should I solve this? Should I use the simple for loop and effectively avoid the warning, or should I use std::copy() and do something to avoid the warning? Obviously, I could disable the warning, but that doesn't seem like a proper solution... or is it?</p>