Boost Users :
From: Nebojsa Simic (nelle_at_[hidden])
Date: 2007-11-17 07:05:03
JOAQUIN LOPEZ MU?Z wrote:
> Hi Nebojsa,
first of all thanks for the swift reply.
> You can't use for_each(it1,it2,someFunctor) to do what you want because
> modify() needs an iterator, and for_each passes a value reference
> to someFunctor rather than the iterator.
Yes, I forgot that ...
> So, you've got to resort to a handmade loop like:
> for(StatisticsByResponse::iterator it=m_statistic.project<1>
> A warning about modifying elements of a multi_index_container in
> a loop: if your modification affects the key on which the index you're
> traversing depends upon, then the loop is broken, because when
> you call modify(...) the element will be rearranged in the index and
> along with it the iterator "it". If this is your case, please read the
> following post where mechanisms for range modifying are provided:
> (Note that post comes with some usable code attached). Hope this
> helps, thanks for using Boost.MultiIndex, if something's still
> not clear do not hesitate to come back.
In this case it is not necessary, because the addStats modifies only the
second index and not idxResponse.
template<typename Index,typename Modifier>
Index& i,typename Index::iterator first,typename Index::iterator last,
typedef std::vector<typename Index::iterator> buffer_type;
v.reserve( last - first ); // would this help boost performance
for(typename buffer_type::iterator it=v.begin(),it_end=v.end();
-- Nebojsa Simic
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