How to use the map_iterator as map index ?

I use a map_iterator.lowerbound to find a value.
If I have the next 'first' values
1
7
8
9

map_iterator= mymap.lower_bound(1); gives me 1

map_iterator= mymap.lower_bound(2); gives me 7

I compare 2 and 7 and decide to use '2' (so I have to decrease 1 unit )
My question is :
Can I decrease my iterator 1 unit?
How can I know the 'index' of the iterator so use in mymap in this way :
mymap[index]. (That is to say how to translate from iterator to 'natural' index )

Thanks

I ask mysefl....
The index is it->first .
And I cas use it++; or advance()

Excuse me


Last edited on
It's called a key. Associative contains "map" a key to a value.

std::map's value_type is a std::pair. std::pair has two values: first and second. You have already discovered that the first is the key.
map iterators support operator++ (both forms) for incrementation and operator-- (both forms) for decrementation.
In addition, std::advance( iter, n ) supports forward iterators in an optimal fashion (random access iterators support operator+( n ) directly, so std::advance() will use that if the iterator supports it, otherwise will use a loop and operator++).
Topic archived. No new replies allowed.