0

I have a variable catch the output of a std::map::find() call, and I wish to check whether or not anything was actually found (i.e. whether or not the iterator that was returned points to map.end()).

//current_state.transitions is a std::map<std::string, std::vector<long>>
auto  map_itr = current_state.transitions.find( std::string( 1, input_string.front() ) );

if ( map_itr == map_itr->second.end() ) {...} // Obviously not working.

I would think that since map_itr and map_itr->second.end() are both iterators, that I would be able to do some sort of comparison between them. I've looked at the documentation for iterator, map, find, etc. and cannot find anything.

solidstatejake
  • 202
  • 3
  • 9
  • 2
    *"i.e. whether or not the iterator that was returned points to `map.end()`"* Have you tried comparing the iterator with `map.end()`? – François Andrieux Feb 14 '20 at 16:20
  • I didn't, but it works, and this question is certainly a duplicate of the link posted. Thank you. Should I delete the question? – solidstatejake Feb 14 '20 at 16:25
  • No, it's best to leave it. Duplicates act as sign posts. Someone might use search terms that could find this question but miss the linked duplicate. In that case, by finding this question, they can make their way to the other question and find answers there. – François Andrieux Feb 14 '20 at 16:29
  • I totally misunderstood what `map::end` meant in the docs. – solidstatejake Feb 14 '20 at 16:30

0 Answers0