title: c++ Looking for a clean and efficient way to get a sub-matrix
body: <p>I am using a vector of vectors to create a 2d array similar to:</p>
  
  <pre><code>std::vector&lt;std::vector&lt;int&gt; &gt; matrix = {
          {1, 2, 3, 4, 4, 6, 7, 8, 9},
          {1, 2, 3, 5, 4, 6, 7, 8, 9},
          {1, 2, 3, 4, 4, 6, 7, 8, 9}
      };
  </code></pre>
  
  <p>Now I would like to extract a sub-matrix with the specification of:</p>
  
  <pre><code>1) all rows
  2) the first 4 columns
  </code></pre>
  
  <p>I am new to <code>c++</code> so the best I've come up with at now is:</p>
  
  <pre><code>if (matrix[n][m-1] &gt;= matrix[n][m])
      {
          std::vector&lt;std::vector&lt;int&gt; &gt; submatrix(3);
          for (int i=0; i &lt; 3; i++) {
              std::vector&lt;int&gt; slice(m);
              for (int j=0; j &lt; m; j++){
                  slice[i] = matrix[i][j];
              }
              submatrix[i] = slice;
          }
          return find_a_peak(submatrix);
      }
  </code></pre>
  
  <p>Where <code>m</code> = 4;</p>
  
  <p>This is only for practice, so please suggest a clean way to do this.  I am a python programmer by training, so in <code>numpy</code> this is quite easy.  But I would like to learn the basics of <code>c++</code> before moving on to third party libraries.</p>