Iterator of Container of Container Based on this question I though I would pull together an iterator that iterated over a container of containers.

template&lt;typename C&gt;
class IteratorForContainerOfContainer
{
    public:
        using Container             = C;
        using ContainerContainer    = typename Container::value_type;
        using Contained             = typename ContainerContainer::value_type;

        using Level1Iter            = typename Container::iterator;
        using Level2Iter            = typename ContainerContainer::iterator;

        using iterator_category     = std::forward_iterator_tag;
        using value_type            = Contained;
        using difference_type       = std::size_t;
        using pointer               = value_type*;
        using reference             = value_type&amp;;


        IteratorForContainerOfContainer(C&amp; c)
            : outerLoop(std::begin(c))
            , outerEnd(std::end(c))
            , innerLoop(std::begin(*outerLoop))
            , innerEnd(std::end(*outerLoop))
        {
            nextValidPos();
        }
        IteratorForContainerOfContainer()
            : outerLoop()
            , outerEnd()
            , innerLoop()
            , innerEnd()
        {}


        IteratorForContainerOfContainer&amp; operator++()
        {
            ++innerLoop;
            nextValidPos();
            return *this;
        }
        value_type&amp; operator*()
        {
            return *innerLoop;
        }
        bool operator!=(IteratorForContainerOfContainer const&amp; rhs) const
        {
            return outerLoop != rhs.outerLoop || innerLoop != rhs.innerLoop;
        }

        private:
            void nextValidPos()
            {
                while ((innerLoop == innerEnd) &amp;&amp; (outerLoop != outerEnd)) {
                    ++outerLoop;
                    if (outerLoop != outerEnd) {
                        innerLoop = std::begin(*outerLoop);
                        innerEnd  = std::end(*outerLoop);
                    }
                }
                if (outerLoop == outerEnd) {
                    outerLoop   = Level1Iter();
                    outerEnd    = Level1Iter();
                    innerLoop   = Level2Iter();
                    innerEnd    = Level2Iter();
                }
            }
            Level1Iter          outerLoop;
            Level1Iter          outerEnd;
            Level2Iter          innerLoop;
            Level2Iter          innerEnd;
};


So an example of simple usage would be:

int main()
{
    using CC = std::vector&lt;std::vector&lt;int&gt;&gt;;
    using It = IteratorForContainerOfContainer&lt;CC&gt;;

    CC   data = {{1,2,3},{4,5,6},{7,8,9}};

     for(It loop(data);loop != It(); ++loop) {
        std::cout &lt;&lt; *loop &lt;&lt; " ";
    }
    std::cout &lt;&lt; "\n";

}
If you try to get an IteratorForContainerOfContainer for an empty container, your constructor will run into Undefined Behavior when it tries to get the inner iterators because the outer container is empty, outerLoop will be the end iterator, and you can't dereference the end iterator.

You're using a default constructed object to double as an end iterator.  Consider adding in a static method to return one, end(C &amp;c), with appropriate changes to nextValidPos.

If you need to work with a const object, you won't be able to get one of these flattened iterators for it.

You don't define operator++(int), so using it++ won't compile.