lundi 6 mars 2017

Get const_reverse_iterator to element from std::map?

I have a unit test doing something like:

// Add element to map (this is done several method calls away from the unit test)

then:

MAP::const_reverse_iterator r_iter(x.getMap().find(key));
assert(myObj.member == r_iter->second.member);                   // This is failing

And I think my assert is failing because my reverse iterator is not pointing to the object with that key, but the one before or after it. When I was only using forward iterators the unit test and assert passed fine.

How do I return a const_reverse_iterator to the same element find(key) would return as a normal iterator?

Aucun commentaire:

Enregistrer un commentaire