JOAQUIN LOPEZ MU?Z wrote:
Hi Nebojsa,
[...] Ola Joaquin, 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> (result.first), it_end=idxResponse.end(); it!=it_end;++it){ idxResponse.modify(it,boost::bind (&Statistics::addStats,::_1,val,tick)); }
perfect.
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:
http://lists.boost.org/boost-users/2006/03/18048.php
(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