Boost logo

Boost :

Subject: Re: [boost] [bind]bind question
From: Max (more4less_at_[hidden])
Date: 2012-05-28 10:46:28


> Ben Pope wrote:
>
> Or even
>
> return do_something_conditional(handle,
> !boost::bind(&pred_a, _1) && boost::bind(&pred_b, _1, n1, n2) );
>
> As for the original error,
>
> error C2664: 'bool std::logical_and<_Ty>::operator ()(const _Ty &,const
_Ty
> &) const' : cannot convert parameter 1 from
'boost::unary_negate<Predicate>'
> to 'const bool &'
>
> the compiler is right, logical_and doesn't accept boost::not1(&pred_a) as
a first
> argument, it takes a bool. To make it compile, one needs to wrap
> boost::not1(&pred_a) in a boost::bind, as follows:
>
> bool do_something(int *handle, int n1, int n2) {
> return do_something_conditional(handle,
> boost::bind(std::logical_and<bool>(),
> boost::bind(boost::not1(&pred_a), _1),
> boost::bind(&pred_b, _1, n1, n2))); }
>
> This will call boost::not1(&pred_a) with _1 instead of passing it as-is to
> logical_and.

Thank you for your swiss army knife, Peter.

Max


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk