title: vector with reinterpret_cast
body: <p>The following code inserts only one value to the vector <code>col</code>.
  The code is extracted from DBMS code base (for importing files), specifically, it is from <a href="https://github.com/TimoKersten/db-engine-paradigms/blob/ae3286b279ad26ab294224d630d650bc2f2f3519/src/common/runtime/Import.cpp#L134" rel="nofollow noreferrer">1</a></p>
  
  <p>The code uses void* to be able to read any field type (int, float, and so on).</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  using namespace std;
  
  void add(std::vector&lt;void*&gt; &amp;col){
    reinterpret_cast&lt;std::vector&lt;int&gt;&amp;&gt;(col).push_back( 1);
    reinterpret_cast&lt;std::vector&lt;int&gt;&amp;&gt;(col).push_back( 2);
    reinterpret_cast&lt;std::vector&lt;int&gt;&amp;&gt;(col).push_back( 13);
  }
  int main() {
   std::vector&lt;void*&gt; col;
  
   add(col);
   cout &lt;&lt; col.size() &lt;&lt; endl;
   for(int i=0;i&lt;col.size();i++)
      cout &lt;&lt;reinterpret_cast&lt;std::vector&lt;int&gt;&amp;&gt; (col)[i] &lt;&lt;endl;
      return 0;
  }
  </code></pre>
  
  <p>I am not sure how this code work?</p>