title: Using c++ std::copy on an array of structure
body: <p>I want to use std::copy to copy an existing array of structures to new one. A regular option is fine with '''local_copy()'''. I want to know the procedure to use std::copy for such case described below -</p>
  
  <p>I tried the code and get following error at compile time</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class BigClass{
  public:
  struct Astruct{
      double x[2], v[2];
      int rank;
  }one_struct;
  
  };
  
  void allocate(struct BigClass::Astruct&amp; one_struct, int i)
  {
  one_struct.x[0] = 1.1;
  one_struct.x[1] = 1.2;
  one_struct.v[0] = 2.1;
  one_struct.v[1] = 2.2;
  one_struct.rank = i;
  }
  
  void local_copy(struct BigClass::Astruct&amp; dest, struct BigClass::Astruct&amp; source)
  {
  dest.x[0] = source.x[0];
  dest.x[1] = source.x[1];
  dest.v[0] = source.v[0];
  dest.v[1] = source.v[1];
  dest.rank = source.rank;
  }
  
  void print(struct BigClass::Astruct one_struct)
  {
  std::cout &lt;&lt; one_struct.rank &lt;&lt; " " &lt;&lt; one_struct.x[0] &lt;&lt; " " &lt;&lt; one_struct.x[1] &lt;&lt; " " &lt;&lt; one_struct.v[0] &lt;&lt; " " &lt;&lt; one_struct.v[1] &lt;&lt; "\n";
  }
  
  
  
  int main(int argc, char *argv[]) {
  
  int size = 10;
  struct BigClass::Astruct BCobj[size];
  for(int i = 0; i &lt; size; i++) allocate(BCobj[i], i);
  for(int i = 0; i &lt; size; i++) print(BCobj[i]);
  
  struct BigClass::Astruct second_BCobj[size];
  //for(int i = 0; i &lt; size; i++) local_copy(second_BCobj[i], BCobj[i]); // this works
  for(int i = 0; i &lt; size; i++) std::copy(BCobj[i+1], BCobj[i], second_BCobj[i]); // not working
  
  for(int i = 0; i &lt; size; i++) print(BCobj[i]);
  
  }
  </code></pre>
  
  <p>The compile time error is following -</p>
  
  <pre><code>/usr/include/c++/7/bits/stl_algobase.h:377:57: error: no type named ‘value_type’ in ‘struct std::iterator_traits&lt;BigClass::Astruct&gt;’
     typedef typename iterator_traits&lt;_II&gt;::value_type _ValueTypeI;
                                                       ^~~~~~~~~~~
  /usr/include/c++/7/bits/stl_algobase.h:378:57: error: no type named ‘value_type’ in ‘struct std::iterator_traits&lt;BigClass::Astruct&gt;’
     typedef typename iterator_traits&lt;_OI&gt;::value_type _ValueTypeO;
                                                       ^~~~~~~~~~~
  /usr/include/c++/7/bits/stl_algobase.h:379:64: error: no type named ‘iterator_category’ in ‘struct std::iterator_traits&lt;BigClass::Astruct&gt;’
     typedef typename iterator_traits&lt;_II&gt;::iterator_category _Category;
                                                              ^~~~~~~~~
  /usr/include/c++/7/bits/stl_algobase.h:383:9: error: no type named ‘value_type’ in ‘struct std::iterator_traits&lt;BigClass::Astruct&gt;’
     const bool __simple = (__is_trivial(_ValueTypeI)
                           ~~~~~~~~~~~~~~~~~~~~~~~~~~
                     &amp;&amp; __is_pointer&lt;_II&gt;::__value
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                     &amp;&amp; __is_pointer&lt;_OI&gt;::__value
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       &amp;&amp; __are_same&lt;_ValueTypeI, _ValueTypeO&gt;::__value);
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/include/c++/7/bits/stl_algobase.h:386:44: error: no type named ‘iterator_category’ in ‘struct std::iterator_traits&lt;BigClass::Astruct&gt;’
     return std::__copy_move&lt;_IsMove, __simple,
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      _Category&gt;::__copy_m(__first, __last, __result);
                          ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
  </code></pre>
  
  <p>Some examples for vectors and int datatypes are available. Could anyone elaborate the appropriate sequence for std::copy for this kind of code structure?
  Thanks.</p>