[MultiIndex] getting the index from set::lower_bound() iterator (or a replacement/extension)
Hi, I need a container like std::set which delivers also the index when using the member function lower_bound(). IMO std::set lacks this important functionality. I cannot use std::distance(myset.begin(), it), because that is very slow as it walks again all the items from the beginning. Can boost MultiIndex be used for this, or any other alternatives/workarounds? Here's a demonstration of what I need: struct TS { /*...*/ }; set<TS> myset; TS S(/*...*/); auto it = myset.lower_bound(S); if (it != myset.end()) { size_t ix = ...howto get the index, ie. the rank?... //... } -- Thx Uenal
U.Mutlu
Hi, I need a container like std::set which delivers also the index when using the member function lower_bound(). IMO std::set lacks this important functionality. I cannot use std::distance(myset.begin(), it), because that is very slow as it walks again all the items from the beginning.
Can boost MultiIndex be used for this [...]?
Not the current version (Boost 1.58), but please take a look at http://article.gmane.org/gmane.comp.lib.boost.user/83882 Joaquín M López Muñoz Telefónica
El 07/05/2015 a las 11:21, Joaquin M Lopez Munoz escribió:
U.Mutlu
writes: Hi, I need a container like std::set which delivers also the index when using the member function lower_bound(). IMO std::set lacks this important functionality. I cannot use std::distance(myset.begin(), it), because that is very slow as it walks again all the items from the beginning.
Can boost MultiIndex be used for this [...]?
Not the current version (Boost 1.58), but please take a look at
Or alternatively use flat_set, it's a sorted vector, so pos = flat_set.lower_bound(...) index = pos - flat_set.begin() Ion
participants (3)
-
Ion Gaztañaga
-
Joaquin M Lopez Munoz
-
U.Mutlu