Std :: equal with reverse_iterator

Is it possible to use reverse_iterator with std::equal ?

For example, any of these legal ones?

 std::equal(v.begin(), v.end(), w.rbegin()) std::equal(v.rbegin(), v.rend(), w.begin()) std::equal(v.rbegin(), v.rend(), w.rbegin()) 
+4
source share
1 answer

All are valid because inverse iterators are, in fact, forward iterators.

A reverse iterator is not a category of iterators. Recall some categories of iterators:

  • An iterator that can be dereferenced ( * ) and enlarged ( ++ ) is the forward iterator.
  • A promising iterator that can also be reduced is a bidirectional iterator.
  • A random access iterator is a biederment iterator that also has the + and - operators.

The reverse iterator, on the other hand, is a bidirectional iterator or random access iterator that accesses the collection in reverse order. Take a look

http://www.cplusplus.com/reference/std/iterator/reverse_iterator/

... especially what he says about iterator_category under the heading "Member Types".

+7
source

Source: https://habr.com/ru/post/1415232/


All Articles