title: std::copy for dynamically allocated pointers
body: <p>This is probably a very newbie question. The class I'm working on (let's call it MyClass) contains the following variables</p>
  
  <pre><code> int nbins;
   double * bins; // = new double[nbins+i]
  </code></pre>
  
  <p>Since I'm implementing a copy constructor</p>
  
  <pre><code> MyClass( const MyClass&amp; source )
  </code></pre>
  
  <p>I need to copy <code>source.bins</code>. I was going to use <code>std::copy</code> from <code>algorithm</code>, but all the examples I've found show how to copy static array like <code>double bins[] = ...</code> or standard data structure like <code>std::vector</code>. I can't find any example in which <code>std::copy</code> is used on pointers like <code>double * bins = new double[nbins+i]</code>. So, my question is: is legal to use <code>std::copy</code> on pointers, like for example</p>
  
  <pre><code>double * bins = new double[nbins+1]; //is this necessary?
  std::copy( std::begin( source.bins ), std::end(source.bins), std::begin(bins) );
  </code></pre>
  
  <p>or should I rather rely on the C <code>memcpy</code></p>
  
  <pre><code>double * bins = new double[nbins+1]; //again, is this necessary?
  memcpy( source.bins, bins, (nbins+1) /* *sizeof(double) ?*/ );
  </code></pre>
  
  <p>So, my questions are basically two:</p>
  
  <p>1) Does <code>std::end(bins)</code> know where is the end of <code>bins (=new double[nbins+1])</code>?</p>
  
  <p>2) Do I need to allocate the memory for the destination before doing the copy? Or the <code>copy</code> (or <code>memcpy</code>) takes care of that?</p>