Why doesn't std :: next accept an InputIterator?

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::nextdoes not accept InputIterators?

One of the options for using the law that I think of is:

first = find(next(first, x), last, 11); // ...

I found a suitable DR :

next/ prevreturns an incremented iterator without changing the value of the original iterator. However, even this can lead to invalidity InputIterator. A ForwardIteratoris required to guarantee the "multipass" property.

But I do not understand how this is related to multipass / invalidation. Using the same multipass / invalidation arguments, we can even disable std::findfor InputIterators:

template<class InputIterator, class T>
InputIterator find(InputIterator first, InputIterator last, const T& value);

std::next std::find std::vector::insert(pos, first, last), InputIterator s

, std::next(it, n) , InputIterator s.

+4
1

, , , , .

std::next , n . , std::next . std::advance n , .

std::next - operator+(T*, size_t). std::advance - operator+=(T*&, size_t). , std::advance, operator+=, void.

, std::find ( ); . , .

+8

All Articles