Is it legal to use a reverse_iterator
with std::equal
?
For example, are any of these legal?
std::equal(v.begin(), v.end(), w.rbegin())
std::equal(v.rbegin(), v.rend(), w.begin())
std::equal(v.rbegin(), v.rend(), w.rbegin())
All are valid, because reverse iterators are , in fact, forward iterators .
"Reverse iterator" is not an iterator category. Remember some iterator categories:
*
) and incremented ( ++
) is a forward iterator. +
and -
operators. On the other hand, a reverse iterator is a bidirectional iterator or a random access iterator that looks at a collection in reverse. Look at
http://www.cplusplus.com/reference/std/iterator/reverse_iterator/
... especially what it says about iterator_category under the "Member types" heading.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.