Jonathan Wakely wrote:
> Always? I've definitely used iter[-1] when dealing with random access iterators and with pointers into arrays. It's more concise than *std::prev(iter), especially if other code nearby is using iter[0] and iter[1].
An iterator is not a container.
While there are reasons to makes sense to used signed values with random access iterators, the fact that you can use iterators in a such a way is a whole set of other problems that I think are of topic for this discussion.
Thiago Macieira wrote:
> But you cannot say the same about the distance between two arbitrary elements in a sequence. You don't know the direction, therefore you must record it. You could just record it with an unsigned and a direction, but that would make APIs like operator+ impossible because of the inability to specify direction.
> In any case, the language says pointer distances are ptrdiff_t and thus signed.
I agree, distances between two arbitrary points should be signed. I don’t see what the confusion is here. A distance is not the same thing as an index.