According to C++11 standard:
24.4.4 Iterator operations [iterator.operations]
§ 7
template <class BidirectionalIterator>
BidirectionalIterator prev(BidirectionalIterator x,
typename std::iterator_traits<BidirectionalIterator>::difference_type n = 1);
Effects: Equivalent to advance(x, -n); return x;
In the same section, but §2 and §3
template <class InputIterator, class Distance>
void advance(InputIterator& i, Distance n);
Requires: n shall be negative only for bidirectional and random access iterators.
Effects: Increments (or decrements for negative n) iterator reference i by n.
Then, for decrementing bidirectional iterators:
24.2.6 Bidirectional iterators
Expression Return type Operational Assertion/note
semantics pre-/post-condition
pre: there exists s such that
--r X& r == ++s.
post: r is dereferenceable.
--(++r) == r.
--r == --s implies r == s.
&r == &--r.
So, it looks like (or at least I couldn't find more relevant part from the standard), that this behavior is not defined.
I'd suggest you to maintain this situation and be careful with my_iter
's value, before passing it to std::prev
.