Boost logo

Boost Users :

Subject: Re: [Boost-users] Problem with nested bind
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2010-08-17 12:32:32


AMDG

przemyslaw.sliwa_at_[hidden] wrote:
> I am trying to make a simple nested bind in boost. I have the fillowing
> structure:
>
> struct eventInterval
> {
> double start, finish, weight;
> };
> and a typedef
>
> typedef boost::shared_ptr<eventInterval> eventIntervalPtr;
>
> and then I am trying to copy (actually push back to a vector) all elements
> which have weight > 0.0. I cannot sompile this bit of code:
>
> std::vector<eventIntervalPtr> posIntervals, negIntervals,
> intervals(eventPtr->decomposeIntervals(anchorDate, today));
>
> std::transform(intervals.begin(), intervals.end(),
> std::back_inserter(posIntervals), boost::bind(std::greater<double>(),
> boost::bind(&eventInterval::weight, _1), 0.0));
>

This is equivalent to
BOOST_FOREACH(item, intervals) {
    posIntervals.push_back(item.weight > 0.0);
}
I don't think this is what you want.

Try
std::remove_copy_if(intervals.begin(), intervals.end(),
    !boost::bind(std::greater<double>(),
        boost::bind(&eventInterval::weight, _1),
        0.0));

In Christ,
Steven Watanabe


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