Boost logo

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