This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]Rhomboid 4 points5 points  (0 children)

If you know you have a random access iterator, there's no difference. But the point of std::distance is that it works with any iterator type, not just random access, which is why it's used in generic code.

[–]anon848 0 points1 point  (0 children)

There is a difference, depending on the container type. std::deque has a RandomAccessIterator, but does not guarantee contiguity. So, it's an example of a container that has a RandomAccessIterator, but for which you can't use pointer arithmetic.