--- 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.
You need '&' in front of the member functions, by the way. Omitting it is a MSVC-ism.
As mentioned in my other e-mail, that worked. I now have a couple of follow-up question about std::auto_ptr in bind: In my program auto_ptr is being used in boost::bind via boost::ref and it works fine. Does this work by design, or coincidence? I couldn't see boost::reference_wrapper and boost::addressof handling std::auto_ptr specially.