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())
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.