The amortized complexity when incrementing the iterator over the whole container is O(1)
per increment, which is all that's required by the standard. You're right that a single increment is only O(log n)
, since the depth of the tree has that complexity class.
It seems likely to me that other RB-tree implementations of map
will be similar. As you've said, the worst-case complexity for operator++
could be improved, but the cost isn't trivial.
It quite possible that the total time to iterate the whole container would be improved by the linked list, but it's not certain since bigger node structures tend to result in more cache misses.