https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122224
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to M Welinder from comment #5) > > std::prev(it, n) is equivalent to std::advance(it, -n) > > Is integer overflow for the negation an issue? https://cplusplus.github.io/LWG/issue3344 > There doesn't seem to be much help in the standard, although > https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator.html (for > "r -= n") shows that at some point this was considered in that context. Yes, that was https://cplusplus.github.io/LWG/issue2519 When a function is specified to be equivalent to some expression involving -n, if the user passes a value of n such that -n is undefined, then they've violated a (possibly implicit) precondition. > Aside: much of the iterator part of the standard feels a bit like a work in > progress. E.g., someone forgot to require that the Distance argument for > std::advance should be integral. Or even arithmetic. It's usually intentional, so that user-defined arithmetic-like types can be used. The STL required integral types, but that was relaxed for the C++98 standard, presumably intentionally.
