title: convert a std::vector of objects from/to a std::vector of unsigned char
body: <p>i have some classes defined as below, only holds some simple datatypes</p>
  
  <pre><code>class A
  {
  public:
    float xxx;
    int yyy;
  }
  </code></pre>
  
  <p>i want to covert a vector of that objects to a vector of unsigned char, and vice versa.
  Is there a quick solution for doing that?</p>
  
  <p>Thanks!</p>
  
  <p>update!</p>
  
  <p>thanks @Maciej Załucki, it's exactly what i need, a great help indeed!
   I refactored your code into the below methods,hope you dont mind.</p>
  
  <pre><code>template&lt;typename T&gt;
  static vector&lt;T&gt; blob_to_vectorT(vector&lt;unsigned char&gt;&amp; buffer) {
      vector&lt;T&gt; result(buffer.size() / sizeof(T));
      memcpy(result.data(), buffer.data(), buffer.size());
      return result;
  }
  
  template&lt;typename T&gt;
  static vector&lt;unsigned char&gt; vectorT_to_blob(vector&lt;T&gt;&amp; dataT) {
      int datasize = sizeof(T) * dataT.size();
      vector&lt;unsigned char&gt; result(datasize);
      memcpy(result.data(), dataT.data(), datasize);
      return result;
  }
  </code></pre>
  
  <p>and i also figured it out in my own way.</p>
  
  <pre><code>template&lt;typename T&gt;
  static vector&lt;T&gt; blob_to_vectorT(vector&lt;unsigned char&gt;&amp; buffer) {
      const T* bytesT = reinterpret_cast&lt;const T*&gt;(&amp;buffer[0]);
      vector&lt;T&gt; result(bytesT, bytesT + buffer.size() / sizeof(T));
      return result;
  }
  
  template&lt;typename T&gt;
  static vector&lt;unsigned char&gt; vectorT_to_blob(vector&lt;T&gt;&amp; dataT) {
      const unsigned char* bytes = reinterpret_cast&lt;const unsigned char*&gt;(&amp;dataT[0]);
      vector&lt;unsigned char&gt; result(bytes, bytes + sizeof(T) * dataT.size());
      return result;
  }
  </code></pre>