title: How to convert a vector<vector<int>> to int** without rebuilding the array?
body: <p>I don't like to use pointers too much and I'm always using stl tools. I've gotten into this situation where I need to pass a int** to a third_party function that needs to work with a 2d array of ints. I have written the following function that creates a vector of int*s to do the job. My question is that is it safe to do this assuming that the third_party function does not change the structure of the array and just accesses the data entries. Is there a better way to do this?</p>
  
  <p>Here is the function def:</p>
  
  <pre><code>void ConvertVectorVectorToIntStarStar(const std::vector&lt;std::vector&lt;int&gt; &gt;&amp; v,vector&lt;int*&gt;* a) {
    assert(a);
    int n = v.size();
    a-&gt;resize(n);
    for(int i = 0; i &lt; n; ++i)
      (*a)[i] = (int*)(&amp;v[i][0]);
  }
  </code></pre>
  
  <p>and this is the usage:</p>
  
  <pre><code>  vector&lt;int*&gt; p;
    ConvertVectorVectorToIntStarStar(v, &amp;p);
    int** a = &amp;p[0];
    third_party_function(a);
  </code></pre>