Boost logo

Boost Users :

From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2005-02-17 14:11:21


Hi Gordon,

Gordon Smith <schmoo2k <at> hotmail.com> writes:

>
> I too have just started to use it and can see many applications (it is very
> kewl) - I have one quick question:
>
> I am using the "boost::multi_index::sequenced<>" to index my list and would
> like the ability to get the actual numeric number for the index (I am using
> to store the zorder for a list of renderers) at the moment I do the
> following:
>
> UniqueIDIndex & index = m_pos.get<1>(); //Index on UniqueID
> UniqueIDIndex::iterator it1 = index.find(id); //Fast get based on
> UniqueID
> GraphItemRendererContainer::iterator it2 = m_pos.project<0>(it1); //Get
> "Index" index
> return std::distance(m_pos.begin(), it2); //Calculate actual position in
> index
>
> Is there any "better" way?
>

I'm afraid not, unless you store the position by other means.
Take into account that this is very inefficient (linear time.)
Recently I proposed adding random-access indices, in the spirit
of std::vectors, which would allow to calculate the position
of an element in constant time. But these indices, if they finally
make it into the lib, won't be available anytime soon --not in
Boost 1.33, at least.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net