Boost logo

Boost Users :

From: Peter Barker (newbarker_at_[hidden])
Date: 2008-09-01 13:00:11


Hello,

I've got some code that works ok with boost::bind and I'm trying to make it work with lambda::bind but am getting compilation errors. Why not leave it as-is? Just above the problem area of code I have another lambda expression and because I've already introduced lambda's _1 placeholder into the current scope and didn't want ambiguities arising so want to convert it over.

I'm using VC++ 7.1 (2003) and Boost 1.35.0.

I've created a stripped down test program to show the compilation problem:

#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include <boost/bind.hpp>
#include <boost/utility.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/lambda/lambda.hpp>

class GridItem : boost::noncopyable
{
public:
 bool AddOption(const char* item,bool unique = true)
 {
  // implementation code omitted!
  return true;
 }
};

void GoodOldBoostBind()
{
 std::auto_ptr<GridItem> item(new GridItem());
 std::vector<std::string> options;

 std::for_each(options.begin(),options.end(),
  boost::bind(GridItem::AddOption,boost::ref(item),boost::bind(std::string::c_str,_1),true));
}

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 *'
        with
        [
            R=bool,
            T=GridItem,
            A1=const char *,
            A2=bool,
            _Ty=GridItem,
            U=std::auto_ptr<GridItem>
        ]
        and
        [
            T=boost::lambda::lambda_functor_base<boost::lambda::action<2,boost::lambda::function_action<2>>,boost::tuples::tuple<const boost::lambda::detail::bind_traits<const char *(__thiscall std::basic_string<char,std::char_traits<char>,std::allocator<char>>::* const )(void) const>::type,const boost::lambda::detail::bind_traits<const boost::lambda::placeholder1_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type,boost::lambda::detail::bind_traits<boost::tuples::null_type>::type>>
        ]
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Can anyone help with this?

Thanks,

Pete


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