I'm studying different types of iterators right now. I've read that std::map
has got bidirectional
iterators. And std::set
, std::list
also have got this type of iterators. Why are they not random access
iterators? Can anyone explain this to me? Thank you!
The Standard C++ library provides random access iterators to container types
for which access to an arbitrary element takes constant time, e.g. std::array
,std::vector
,
std::deque
. That is because
a random access container is one of
which any element can be accessed in constant time.
std::list
is not a random access container type:
access takes linear time. Neither is std::set
: access
takes logarithmic time. Likewise std::map
.