The behavior of const_reverse_iterator is different from the behavior of const_iterator, due to having no mixed const/non-const equality or inequality operators. Consider the following code:
#include <map> #include <iostream> using std::map; using std::cout; using std::endl; using std::string; void test1() { map< int, string > map1; map1[ 0 ] = "test1"; map1[ 1 ] = "test2"; typedef map< int, string >::const_iterator conit; // The following is okay because although map1.end() // returns a non-const iterator, const_iterator has a // mixed const/non-const inequality operator defined. for( conit cit = map1.begin() ; cit != map1.end() ; ++cit ) cout << ( *cit ).second << endl; } void test3( const map< int, string > &map1 ) { typedef map< int, string >::const_reverse_iterator conit; // The following is okay, because map1.rend() returns // a const_reverse_iterator for( conit cit = map1.rbegin() ; cit != map1.rend() ; ++cit ) cout << ( *cit ).second << endl; } void test2() { map< int, string > map1; map1[ 0 ] = "test1"; map1[ 1 ] = "test2"; typedef map< int, string >::const_reverse_iterator conit; test3( map1 ); // The following line fails to compile: // map1.rend() returns a non-const reverse_iterator // and there is no mixed inequality operator for( conit cit = map1.rbegin() ; cit != map1.rend() ; ++cit ) cout << ( *cit ).second << endl; } int main() { test1(); test2(); return 0; } -- Summary: const_reverse_iterator does not have a mixed equality or inequality operator Product: gcc Version: 3.3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: schaudhu at blackrock dot com http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26887