Boost logo

Boost Users :

Subject: [Boost-users] Boost lambda bind and boost smart_ptr issue
From: Brian Martin (brian.tensor_at_[hidden])
Date: 2010-06-08 20:26:11


Hi all,

I have a problem involving Boost Lambda and shared_ptr. Although this has
come up before, my problem is a little different.

Essentially, I have classes derived from bases that contain pure virtuals.
These are stored in STL
containers as shared_ptrs (to the base) and to avoid having to write all
those pesky
functions/functors for STL algorithms, it would be nice to use Lambda
instead.
The following is similar to the sort of code I'm writing:

class shape
{
public:
    virtual void draw(const int)=0;
};

class rectangle : public shape
{
public:
    virtual void draw(const int x){std::cout << "rectangle::draw() with x =
" << x << "\n";}
};

class circle : public shape
{
public:
    virtual void draw(const int x) {std::cout << "circle::draw() with x =
" << x << "\n";}
};

vector< shared_ptr<shape> > shapes;

// assume I stick stuff into shapes...

for_each(shapes.begin(), shapes.end(), bind(&shape::draw, _1, 2));

The last statement fails under VC++ 2008 with
error C2665: 'boost::lambda::function_adaptor<Func>::apply' : none of the 2
overloads could convert all the argument types

This works if you use boost::bind instead of the lambda bind.

The rest of the error message (too lengthy to list) seems to be telling me
that there is an ambiguity between the two
following types:
Result boost::lambda::function_adaptor<Func>::apply<RET,A3>(Result
(__thiscall shape::* )(Arg1),Object *,A1 &)
Result boost::lambda::function_adaptor<Func>::apply<RET,A3>(Result
(__thiscall shape::* )(Arg1),Object &,A1 &)

I really could use a solution to this since it's stopping me from using
lambda more often.
Thanks in advance, Brian Martin



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