Boost logo

Boost Users :

Subject: Re: [Boost-users] using bind with find_if
From: Dennis Jones (djones_at_[hidden])
Date: 2011-03-09 21:36:40


"Igor R" <boost.lists_at_[hidden]> wrote in message
news:AANLkTimdhsHw+Ow8VAfrNZQe=5g79R9KudWiokwN8a54_at_mail.gmail.com...
>> I just have to add:
>>
>> typedef bool result_type;
>>
>> to my functor, or call boost::bind<bool>.
>
> Or just define a simple function instead of the functor (which is
> stateless anyway).

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> > >'

This is odd, because the arguments are const and the parameters in the
function are declared as const. It seems to me that it should compile, but
doesn't. Why not? (compiler bug?) Now, if I remove the 'const' from the
integer parameter declarations, or if I make them const references, it
compiles fine.

- Dennis


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