|
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