Boost logo

Boost :

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

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

This should happen for each object in the vector (_1).

I get various types of compiler errors on MSVC9. They all have to do with

: error C2780: 'const
Arg1,const Arg2,const Arg3,const Arg4,const Arg5,const Arg6,const
Arg7,const Arg8,const Arg9,const Arg10>::type>> boost::lambda::bind(const
Arg1 &,const Arg2 &,const Arg3 &,const Arg4 &,const Arg5 &,const Arg6
&,const Arg7 &,const Arg8 &,const Arg9 &,const Arg10 &)' : expects 10
arguments - 2 provided
: see declaration of 'boost::lambda::bind'

Anyone have any idea what I'm doing wrong?

Robert Dailey

Boost list run by bdawes at, gregod at, cpdaniel at, john at