[lambda] Can't get simple lambda working...

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 C2780: 1>c:\code\work\cmake-mds\server\gmmserver\domino\server\interface\dimime.cpp(287) : error C2780: 'const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<10,boost::lambda::function_action<10,T>>,detail::bind_tuple_mapper<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 1> c:\code\work\cmake-mds\build-vc9\third_party\boost\1.48.0\include\boost\lambda\detail\bind_functions.hpp(1743) : see declaration of 'boost::lambda::bind' Anyone have any idea what I'm doing wrong? --------- Robert Dailey

Seems to be a problem with the std::vector being passed in as const reference. If I remove the const qualifier it compiles fine. MessageAttachment::name() is defined as const so it should work; no idea why const breaks it. --------- Robert Dailey On Mon, Mar 19, 2012 at 5:44 PM, Robert Dailey <rcdailey@gmail.com> 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".
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 C2780:
1>c:\code\work\cmake-mds\server\gmmserver\domino\server\interface\dimime.cpp(287) : error C2780: 'const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<10,boost::lambda::function_action<10,T>>,detail::bind_tuple_mapper<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 1> c:\code\work\cmake-mds\build-vc9\third_party\boost\1.48.0\include\boost\lambda\detail\bind_functions.hpp(1743) : see declaration of 'boost::lambda::bind'
Anyone have any idea what I'm doing wrong?
--------- Robert Dailey

Actually never mind. It still doesn't work when I remove const. Apologies for the confusion. I'm back to square one. --------- Robert Dailey On Mon, Mar 19, 2012 at 6:02 PM, Robert Dailey <rcdailey@gmail.com> wrote:
Seems to be a problem with the std::vector being passed in as const reference. If I remove the const qualifier it compiles fine. MessageAttachment::name() is defined as const so it should work; no idea why const breaks it.
--------- Robert Dailey
On Mon, Mar 19, 2012 at 5:44 PM, Robert Dailey <rcdailey@gmail.com> 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".
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 C2780:
1>c:\code\work\cmake-mds\server\gmmserver\domino\server\interface\dimime.cpp(287) : error C2780: 'const boost::lambda::lambda_functor<boost::lambda::lambda_functor_base<boost::lambda::action<10,boost::lambda::function_action<10,T>>,detail::bind_tuple_mapper<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 1> c:\code\work\cmake-mds\build-vc9\third_party\boost\1.48.0\include\boost\lambda\detail\bind_functions.hpp(1743) : see declaration of 'boost::lambda::bind'
Anyone have any idea what I'm doing wrong?
--------- Robert Dailey

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

On Mon, Mar 19, 2012 at 6:05 PM, Eric Niebler <eric@boostpro.com> 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
On 3/19/2012 3:44 PM, Robert Dailey wrote: 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

Robert Dailey wrote
On Mon, Mar 19, 2012 at 6:05 PM, Eric Niebler <eric@> wrote:
On 3/19/2012 3:44 PM, Robert Dailey wrote:
Here is a basic function I have:
A side note not directly related to your issue: Consider using Boost.Phoenix instead of Boost.Lambda (Boost.Lambda is "obsolete" and it was replaced by the more powerful Boost.Phoenix). --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/lambda-Can-t-get-simple-lambda-working-tp... Sent from the Boost - Dev mailing list archive at Nabble.com.

On Tue, Mar 20, 2012 at 9:51 AM, lcaminiti <lorcaminiti@gmail.com> wrote:
Robert Dailey wrote
On Mon, Mar 19, 2012 at 6:05 PM, Eric Niebler <eric@> wrote:
On 3/19/2012 3:44 PM, Robert Dailey wrote:
Here is a basic function I have:
A side note not directly related to your issue: Consider using Boost.Phoenix instead of Boost.Lambda (Boost.Lambda is "obsolete" and it was replaced by the more powerful Boost.Phoenix).
Ok. Is it available in version 1.48? Why was boost.lambda deprecated in favor of this new library?

On Tue, Mar 20, 2012 at 4:14 PM, Robert Dailey <rcdailey@gmail.com> wrote:
A side note not directly related to your issue: Consider using Boost.Phoenix instead of Boost.Lambda (Boost.Lambda is "obsolete" and it was replaced by the more powerful Boost.Phoenix).
Ok. Is it available in version 1.48? Why was boost.lambda deprecated in favor of this new library?
For this code I'd just use a plain old for loop. -- Olaf

Robert Dailey wrote
On Tue, Mar 20, 2012 at 9:51 AM, lcaminiti <lorcaminiti@> wrote:
Robert Dailey wrote
On Mon, Mar 19, 2012 at 6:05 PM, Eric Niebler <eric@> wrote:
On 3/19/2012 3:44 PM, Robert Dailey wrote:
Here is a basic function I have:
A side note not directly related to your issue: Consider using Boost.Phoenix instead of Boost.Lambda (Boost.Lambda is "obsolete" and it was replaced by the more powerful Boost.Phoenix).
Ok. Is it available in version 1.48? Why was boost.lambda deprecated in favor of this new library?
I don't think Boost.Lambda will (ever) be removed from Boost but David Abrahams once suggested to consider Lambda deprecated in favor of Phoenix (I can't find that email right now...) so I'm spreading the word :) Phoenix allows you to do what Lambda does plus much more -- definitely take a look at it if you have time. HTH, --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/lambda-Can-t-get-simple-lambda-working-tp... Sent from the Boost - Dev mailing list archive at Nabble.com.

On Tue, Mar 20, 2012 at 3:00 PM, lcaminiti <lorcaminiti@gmail.com> wrote:
I don't think Boost.Lambda will (ever) be removed from Boost but David Abrahams once suggested to consider Lambda deprecated in favor of Phoenix (I can't find that email right now...) so I'm spreading the word :) Phoenix
Here's the reference and a link: On Thu, Dec 1, 2011 at 3:57 PM, Dave Abrahams <dave@boostpro.com> wrote:
5. Can we please, finally, *deprecate* Boost.Lambda and put a sign on its docs directing people to look at Phoenix?
http://lists.boost.org/Archives/boost/2011/12/188549.php --Lorenzo
participants (6)
-
Eric Niebler
-
lcaminiti
-
Lorenzo Caminiti
-
Mathias Gaunard
-
Olaf van der Spek
-
Robert Dailey