Boost logo

Boost Users :

Subject: Re: [Boost-users] multi_index_comtainer questions
From: Andrew Holden (aholden_at_[hidden])
Date: 2009-10-13 10:56:27


On Tuesday, October 13, 2009 9:53 AM, Vladimir Voronkov wrote:
> Hi, All,
>
> I just have started using boost and have some questions, answers
> on that i couldn’t find in the documentation.
>
> My interest is in using multi_index_container as combination of
> advantages of standard bidirectional list as well as fast lookup
> (insertion) of standard associative container (particularly set).
>
> Let’s say we have the following definitions:
>
>            typedef boost::multi_index_container<
>                  UserInfo,
>                  boost::multi_index::indexed_by<
>                        boost::multi_index::sequenced<>,
>                        boost::multi_index::ordered_unique<
>                             boost::multi_index::identity<UserInfo>,
>                             UserInfoLess> > >
>            UsersContainer;
>
>            typedef UsersContainer::nth_index<0>::type UsersList;
>            typedef UsersContainer::nth_index<1>::type UsersSet;
>
>
> Now we want to insert some value into this container the following way:
>
>            UsersSet& setIndex = m_Users.get<1>();
>            std::pair<UsersSet::iterator, bool> insRet = setIndex.insert(someVal);
>
>The question is how can i acquire iterator of m_Users having the
> iterator UsersSet::iterator ? Do iterators keep the property of set’s
> iterators that they remain valid after insertion of an element?
>
> Thanks for the answers,
> Vladimir Voronkov.

I would recommend reading up on iterator projection.

http://www.boost.org/doc/libs/1_40_0/libs/multi_index/doc/tutorial/basics.html#projection

As far as I know, all iterators to all indices of a multi-index remain valid unless they point to a deleted element.


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