Iterator for multi-dimensional vector that is used as unidimensional?
<p>I have a vector that looks like this:</p>

<pre><code>std::vector&lt;std::vector&lt;MyClass&gt;&gt; myVector;
</code></pre>

<p>And I would like to access its elements through iterators as if it was an unidimensional vector:</p>

<pre><code>for (auto&amp; x : myVector)
{
     foo(x); // x is an object of type MyClass
}
</code></pre>

<p>(i.e. the fact that there are multiple dimensions is transparent to whoever loops through myVector)</p>

<p>I have an idea of how this should be done, have a custom iterator implementation that saves current indexes so that when one of the vectors has no more elements, it resets one of the indexes and increments the other so that it can start iterating through the next vector and so on. But I have been trying to code this idea but can't seem to get this working. Does anyone have any idea of how I can possibly achieve this? Or even better, if there's any open-source project that has a similar implementation?</p>

<p>Thanks.</p>