c++ - What is meant by map/set iterator not decrementable? How to make map.rbegin()->first work? -


i trying last element in map of map_of_bit_to_parent

map<long long, long long> ::reverse_iterator itr_rel = map_of_bit_to_parent.rbegin(); long long total_parent_rels = itr_rel->first; 

but assignment caused run time error " map/set iterator not decrementable"

how make such assignments?

always test validity of iterator before accessing data through it.

map<long long, long long> ::reverse_iterator itr_rel = map_of_bit_to_parent.rbegin(); long long total_parent_rels = 0; if ( itr_rel != map_of_bit_to_parent.rend() ) {    total_parent_rels = itr_rel->first; } 

Comments

Popular posts from this blog

javascript - How to diff two immutable objects -

c# - How can I have the VS Debugger break in the correct location for exceptions thrown in Async methods in a Console App? -

javascript - React.js: onClick function from child to parent -