Boost logo

Boost Users :

From: Peter Barker (newbarker_at_[hidden])
Date: 2008-09-02 07:22:27


--- On Mon, 1/9/08, Peter Dimov <pdimov_at_[hidden]> wrote:

> From: Peter Dimov <pdimov_at_[hidden]>
> Subject: Re: [Boost-users] [bind] [lambda] making lambda::bind work
> To: boost-users_at_[hidden]
> 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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net