"tomek milewski" <mi*************@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
Hello,
I have a map with keys that can be compared each other. I need a
method that returns the lowest and the greatest key from that map.
Now I'm using begin() and rbegin() which gives iterators to first and
last element of the map.
My question is:
Does begin() and rbegin() guarantee that returned iterators point on
the pair with lowest and gratest value?
begin() and rbegin() are specified to give you the first and the last
element in the container. Whether these are the ones with the lowest and the
greatest value depends on your sorting predicate. The standard map uses the
less<operator and thus, all elements in the container will be sorted
ascending if you do not specify otherwise.
Simple test (using gcc) shows it is true, but I've found comments it
is not.
Are you sure that those comments did not refer to user specified sorting
like the following:
map<T, T, std::greater<T MyMap;
which would give you a map with descending order.
HTH
Chris