title: Get the first column of a matrix represented by a vector of vectors
body: <p>Suppose I'm representing a matrix <code>foo</code> of values using <code>std::vector</code>:</p>
  
  <pre><code>int rows = 5;
  int cols = 10;    
  auto foo = vector&lt;vector&lt;double&gt;&gt;(rows, vector&lt;double&gt;(cols));
  </code></pre>
  
  <p>Is there a cleverly simple way for me to get a <code>vector&lt;int&gt;</code> of size <code>rows</code> that contains the first "column" of foo:</p>
  
  <pre><code>{foo[0][0], foo[0][1], foo[0][2], foo[0][3], foo[0][4] }
  </code></pre>
  
  <p>Put another way, can I "transpose" foo so that the following three things are true:</p>
  
  <pre><code>foo_transpose.size() == cols
  foo_transpose[0].size() == rows
  foo_transpose[0] == {foo[0][0], foo[0][1], foo[0][2], foo[0][3], foo[0][4] }
  </code></pre>
  
  <h2>Clarifying Note</h2>
  
  <p>There are a few good suggestions for alternative ways to represent a "matrix". When I use the term "matrix" I simply mean that each of the second level <code>vector</code>'s will be the same size. I don't mean to suggest that I will be using this data structure for linear algebra type operation. I actually DO need a vector of vectors, or a data structure from which you can "pull out" 1D vectors, because I have functions that operate on vectors like:</p>
  
  <pre><code>double sum(vector&lt;double&gt; const &amp; v);
  </code></pre>
  
  <p>That I call by:</p>
  
  <pre><code>sum(foo[0]);
  </code></pre>
  
  <p>It's just in a special case I came up to a situation that need to do:</p>
  
  <pre><code>sum({foo[0][0], foo[0][1], foo[0][2], foo[0][3], foo[0][4] };
  </code></pre>
  
  <h2>For Loop Solution</h2>
  
  <p>There is an obvious for loop solution, but I was looking for something more robust and efficient.</p>