|
Boost Users : |
From: Nebojsa Simic (nelle_at_[hidden])
Date: 2007-11-16 16:56:06
Nebojsa Simic wrote:
> Hello all,
>
> First of all, thanks for a wonderful library, it is a pleasure to work
> with...
>
> However I ran into some problems and I can not find the answers either
> on the Internet nor on this mailing list. The problem at hand concerns
> the multiindex container and bind.
>
> I have a class with the following member:
>
> class Statistics {
> public:
> void addStats ( double val, int tick );
> }
>
> and a container:
>
> typedef multi_index_container< Statistics,
> indexed_by <ordered_unique<identity<Statistics> >,
> ordered_non_unique< member<Statistics,double,&Statistics::gamma> >
> >
> > StatisticsMap;
>
> StatisticsMap m_statistic;
>
> indexed by :
>
> typedef StatisticsMap::nth_index<1>::type StatisticsByResponse;
>
> somewhere in code i try to do this :
>
> std::pair<StatisticsMap::iterator,bool> result = m_statistic.insert(
> Statistics( response, value, tick ) );
>
> StatisticsByResponse& idxResponse = m_statistic.get<1>();
> StatisticsByResponse::iterator it = m_statistic.project<1>(result.first );
>
> the problem comes when I try to update the statistics by using :
>
> for_each( it
> , idxResponse.end()
> , boost::bind( &Statistics::addStats, ::_1, val, tick )
> );
>
Ok, the elements in the container are constant and may not be changed
through iterators. For multiindex container the modify method must be
used to change them.
So I changed the last line to :
boost::function<void(Statistics&)> fnAddStats = boost::bind(
&Statistics::addStats, ::_1, val, tick );
for_each( it
, idxResponse.end()
, boost::bind( &StatisticsByResponse::modify,
boost::ref(idxResponse), ::_1, fnAddStats )
);
but it still does not compile (problem with boost::bind "wrong number of
arguments").
the call :
idxResponse.modify( it, fnAddStats );
works, so the problem is not the first bind, but the one in for_each.
-- 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