Boost logo

Boost :

Subject: Re: [boost] [lambda] Can't get simple lambda working...
From: Robert Dailey (rcdailey_at_[hidden])
Date: 2012-03-19 19:10:57


On Mon, Mar 19, 2012 at 6:05 PM, Eric Niebler <eric_at_[hidden]> wrote:

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

Thanks! This helped a lot. I had to make a minor adjustment to the syntax
for constness:

            bind( static_cast<char const* (MessageAttachment::*)() const>(
&MessageAttachment::name ), _1 ) == filename


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