[multi-index] looking for "not greater than"
Hello, I've got a container with an ordered non-unique key. I have to find an element, which is not greater than X. [1, 3, 3, 5, 7] myIndex.not_greater_than(4) --> 5 myIndex.not_greatet_than(7) --> 7 myIndex.not_greatet_than(8) --> 7 IUUC, neither lower_bound(), nor upper_bound() can help here. Is there a simple way to do this? Thanks.
Hi,
I've got a container with an ordered non-unique key. I have to find an element, which is not greater than X.
Is this a homework? I hope not :-)
[1, 3, 3, 5, 7] myIndex.not_greater_than(4) --> 5 myIndex.not_greatet_than(7) --> 7 myIndex.not_greatet_than(8) --> 7
IUUC, neither lower_bound(), nor upper_bound() can help here. Is there a simple way to do this?
What I use is get an upper_bound and decrement the iterator. Of course, depending on the situation, you may also use reverse ordering and lower_bound. Cheers, Filip
Is this a homework? I hope not :-)
I had done all my homeworks many years ago :).
What I use is get an upper_bound and decrement the iterator. Of course, depending on the situation, you may also use reverse ordering and lower_bound.
Ok, thanks. I just thought there might be some more direct & elegant way that I missed.
Igor R escribió:
Hello,
I've got a container with an ordered non-unique key. I have to find an element, which is not greater than X.
[1, 3, 3, 5, 7] myIndex.not_greater_than(4) --> 5 myIndex.not_greatet_than(7) --> 7 myIndex.not_greatet_than(8) --> 7
IUUC, neither lower_bound(), nor upper_bound() can help here. Is there a simple way to do this?
Take a look at range-retrieving member functions: http://www.boost.org/libs/multi_index/doc/tutorial/basics.html#range Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Take a look at range-retrieving member functions:
http://www.boost.org/libs/multi_index/doc/tutorial/basics.html#range
Ah, right, that's what I was looking for! Thanks.
participants (3)
-
Filip Konvička
-
Igor R
-
joaquin@tid.es