|
Boost Users : |
Subject: Re: [Boost-users] using bind with find_if
From: Igor R (boost.lists_at_[hidden])
Date: 2011-03-10 05:50:03
> Thanks for the suggestion. Â However, this:
>
> bool OverrideMatches(
> Â Â const TItemOverride &OverrideSource,
> Â Â const RecNo_t ChildItemRecNo, Â Â <-- note: these are const
> Â Â const RecNo_t LinkItemRecNo )
> {
> Â return
> Â Â OverrideSource.ChildAssyItemRecNo == ChildItemRecNo &&
> Â Â OverrideSource.LinkItemRecNo == LinkItemRecNo;
> }
>
> const RecNo_t ChildItemRecNo = 123; Â <-- note: these are const too
> const RecNo_t LinkItemRecNo = 456;
>
> std::find_if(
> Â Â FOverridesContainer.begin(),
> Â Â FOverridesContainer.end(),
> Â Â boost::bind(OverrideMatches, _1, ChildItemRecNo, LinkItemRecNo) );
>
>
> results in an error:
>
> [C++ Error] bind_cc.hpp(50, 4): E2034 Cannot convert
> '_bi::bind_t<bool,bool (*)(const TItemOverride &,const unsigned int,const
> unsigned int),_bi::list3<arg<1> (*)(),_bi::value<const unsigned
> int>,_bi::value<const unsigned int> > >' to
> '_bi::bind_t<bool,bool (*)(const TItemOverride &,unsigned int,unsigned
> int),_bi::list3<arg<1> (*)(),_bi::value<const unsigned int>,_bi::value<const
> unsigned int> > >'
What version do you use? I 1.45 the following compiles well:
#include <vector>
#include <algorithm>
#include <boost/bind.hpp>
struct element
{
int a_;
int b_;
};
bool compare(const element &el, const int a, const int b)
{
return el.a_ == a && el.b_ == b;
}
int main()
{
using std::vector;
vector<element> v;
vector<element>::iterator curr = std::find_if(v.begin(), v.end(),
boost::bind(compare, _1, 1, 2));
}
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