--- On Mon, 1/9/08, Peter Dimov <pdimov@pdimov.com> wrote:
From: Peter Dimov <pdimov@pdimov.com> Subject: Re: [Boost-users] [bind] [lambda] making lambda::bind work To: boost-users@lists.boost.org Date: Monday, 1 September, 2008, 6:13 PM Peter Barker:
void LambdaBind() { std::auto_ptr<GridItem> item(new GridItem()); std::vector<std::string> options;
using namespace boost::lambda; using boost::lambda::_1; std::for_each(options.begin(),options.end(),
bind(GridItem::AddOption,boost::ref(item),bind(std::string::c_str,_1),true));
// COMPILE ERROR ON ABOVE }
int main() { }
The error is:
c:\releases\lib\boost\boost_1_35_0\include\boost\bind.hpp(338) : error
C2664: 'R boost::_mfi::mf2<R,T,A1,A2>::operator ()<std::auto_ptr<_Ty>>(const U &,A1,A2) const' : cannot convert parameter 2 from 'boost::lambda::lambda_functor<T>' to 'const char *'
Since you use an unqualified call to bind, argument-dependent lookup finds boost::bind and prefers it as a better match. Nasty.
Thank you! It took me a while to figure out which argument made the compiler choose boost::bind. It was boost::ref(). After replacing that with var() I still had a compiler error as lambda::bind doesn't seem to work out of the box with std::auto_ptr. The following compiled: void LambdaBind() { GridItem item; std::vector<std::string> options; using namespace boost::lambda; using boost::lambda::_1; std::for_each(options.begin(),options.end(), bind(&GridItem::AddOption,var(item),bind(&std::string::c_str,_1),true)); // NO COMPILE ERROR ON ABOVE :-) }
You need '&' in front of the member functions, by the way. Omitting it is a MSVC-ism.
Ahh - I'm glad to learn that. Many thanks for your help.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users