Boost logo

Boost :

Subject: Re: [boost] [lambda] Can't get simple lambda working...
From: Eric Niebler (eric_at_[hidden])
Date: 2012-03-19 19:05:24


On 3/19/2012 3:44 PM, Robert Dailey wrote:
> Here is a basic function I have:
>
>
> bool MimeDocument::GetExistingAttachment(
> std::string const& filename,
> std::vector<MessageAttachment> const& attachments,
> MessageAttachment& attachment
> )
> {
> using namespace boost::lambda;
> using boost::lambda::_1;
>
> std::vector<MessageAttachment>::const_iterator it =
> std::find_if( attachments.begin(), attachments.end(),
> bind( &MessageAttachment::name, _1 ) == filename
> );
>
> if( it != attachments.end() ) {
> attachment = *it;
> return true;
> }
>
> return false;
> }
>
> MessageAttachment::name() has 2 overloads, one that takes 1 parameter and
> the other that takes no parameter. I'm attempting to call the version that
> accepts no parameters and returns a "char const*". I want to then compare
> this value to the local variable "filename".
<snip>

If a function is overloaded, you have to help the compiler choose the
right overload when you take the function's address. So replace &
MessageAttachment::name with something like:

  static_cast< char const* (MessageAttachment::*)() >(
&MessageAttachment::name )

Hope I got the syntax right.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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