Reimplemented the flat_iterator as a correct random-access iterator that works with the STL.