I'm having trouble iterating in reverse over a map in gcc c++. When I use a reverse iterator, it seems I can't assign anything to it - the compiler complains. I'm working around it with some awkward code using a forward iterator, but it's not very elegant. Any thoughts?
+3
A:
You mean something like:
std::map<std::string, std::string> theMap;
/* do stuff */
for (std::map<std::string, std::string>::reverse_iterator iter = theMap.rbegin(); iter != theMap.rend(); ++iter)
{
/* do more stuff */
}
Does not work? When you say "the compiler complains", we can only guess so much. How does it complain? Error? Warning?
GMan
2009-04-08 22:40:51
typename is not required there
anon
2009-04-08 22:45:16
Oops, I've been writing a lot of templated stuff lately, I removed it, thanks. :X
GMan
2009-04-08 22:48:46
-1 because?... :(
GMan
2009-04-08 22:56:12
+3
A:
You should check, how you obtain iterator range ( it should be rbegin()/rend() instead begin()/end() ). Do you really use reverse_iterator ( not const_reverse_iterator )?
bb
2009-04-08 22:46:36