 <p>There is no built-in looping for nested structures (given the depth of nesting could be arbitrary). You have several options.</p> <p>Flatten the 2D vector into a single dimensional vector and iterate over that or, Use something like <code>for_each</code>, e.g.</p> <pre><code>template &lt;typename T&gt; struct do_foo { void operator()(T v) { // Use the v } }; template &lt;typename Handler, typename Container&gt; struct handle_nested { void operator()(Container const&amp; internal) { // inner loop, container type has been abstracted away and the handler type for_each(internal.begin(), internal.end(), Handler()); } }; // outer loop for_each(foo.begin(), foo.end(), handle_nested&lt;do_foo&lt;int&gt;, std::vector&lt;int&gt; &gt;()); </code></pre>