On 2007-11-08 05:02:48 -0500, "Pascal" <No****@NoSpam.NoSpamsaid:
I'm using a map for storing information.
With lower_bound i can find keys equal to or greater then the key i give as
a parameter. With upper_bound i can find keys greater then the key i give as
a parameter.
What i want is find keys less then or equal to the key i give. Is that
possible with a map? After googling for 1 hour, it seems that nobody ever
needed this functionality :-)
Remember, iterators work in pairs: [first, last) is a sequence of
elements. When you call upper_bound you get an iterator 'res' that
points at the first element in [first, last) whose key is greater than
the key you passed. So the sequence [res, last) is the sequence of
elements with keys that are greater than the key. Now think of 'res' as
the end instead of the subsequence instead of the beginning: the
sequence [first, res) is all the elements with keys that are less than
or equal to the given key.
Similarly, if you call lower_bound, its result gives you a subsequence
[first, res) whose elements all have keys that are less than the given
key.
--
Pete
Roundhouse Consulting, Ltd. (
www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(
www.petebecker.com/tr1book)