ISO C++11 24.3:
template <class InputIterator, class Distance>
void advance(InputIterator& i, Distance n);
// ...
template <class ForwardIterator>
ForwardIterator next
(
ForwardIterator x,
typename std::iterator_traits<ForwardIterator>::difference_type n = 1
);
Why std::next
does not accept InputIterator
s?
One of legal use cases I am thinking about is:
first = find(next(first, x), last, 11); // ...
I have found appropriate DR:
next
/prev
return an incremented iterator without changing the value of the original iterator. However, even this may invalidate anInputIterator
. AForwardIterator
is required to guarantee the 'multipass' property.
But I don't understand how multipass/invalidation is related to that. Using same multipass/invalidation reasoning, we can even ban std::find
for InputIterator
s:
template<class InputIterator, class T>
InputIterator find(InputIterator first, InputIterator last, const T& value);
There is nothing special about std::next
in compare to std::find
or std::vector::insert(pos, first, last)
which have perfectly legal use cases for InputIterator
s
Moreover std::next(it, n)
can be used in generic code, which operates not only on InputIterator
s.
std::advance
to more accurately convey your semantics for InputIterators. We've been over this in chat – sehe Oct 27 '13 at 0:15InputIterator
. I am interested to hear objective reasons. – Evgeny Panasyuk Oct 27 '13 at 0:16