Re: [Boost-users] Boost Lambda Newbie question

Hi, I'm experimenting with the boost lambda library, and I wrote the following code, to go through the vector of numbers and print out statements if the number is greater than 5 or less than 5 int a[]={1,2,3,4,5,6,7,8,9,10,10,9,8,4,7,6,5,4,3,3,1}; std::vector<int> v(a,a+sizeof(a)/sizeof(int)); std::for_each ( v.begin() , v.end() , (if_(_1<5)[ std::cout<

Hi, How can we use the Boost::lambda::bind function to behave the same as the following class some_class{ public: some_class& foo(int x){....} void bar() {...} } some_class a_object; a_object.foo(x).bar(), where the call to some_class::foo returns a reference to the object. I could use Boost.Bind library to accomplish the above as follows boost::bind(&some_class::bar, boost::bind(&some_class::foo, some_functor(), _1)) and I need to do this using boost.lambda. Thanks, Haroon

Can you post a full example (with main, includes and all)? Jaakko On Nov 27, 2006, at 9:41 PM, Haroon Khan wrote:
Hi, How can we use the Boost::lambda::bind function to behave the same as the following
class some_class{ public: some_class& foo(int x){....} void bar() {...} }
some_class a_object; a_object.foo(x).bar(), where the call to some_class::foo returns a reference to the object.
I could use Boost.Bind library to accomplish the above as follows boost::bind(&some_class::bar, boost::bind(&some_class::foo, some_functor(), _1))
and I need to do this using boost.lambda.
Thanks, Haroon _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I managed to solve the problem, as shown in the code below. I had
mixed up the Boost.Bind and Boost.Lambda , and totally confused
myself.
Thanks, Haroon
struct some_functor
{
private:
int x_;
public:
some_functor& foo(int x)
{
std::cout<
Can you post a full example (with main, includes and all)?
Jaakko
On Nov 27, 2006, at 9:41 PM, Haroon Khan wrote:
Hi, How can we use the Boost::lambda::bind function to behave the same as the following
class some_class{ public: some_class& foo(int x){....} void bar() {...} }
some_class a_object; a_object.foo(x).bar(), where the call to some_class::foo returns a reference to the object.
I could use Boost.Bind library to accomplish the above as follows boost::bind(&some_class::bar, boost::bind(&some_class::foo, some_functor(), _1))
and I need to do this using boost.lambda.
Thanks, Haroon _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Nov 27, 2006, at 1:14 AM, Haroon Khan wrote:
Hi, I'm experimenting with the boost lambda library, and I wrote the following code, to go through the vector of numbers and print out statements if the number is greater than 5 or less than 5
int a[]={1,2,3,4,5,6,7,8,9,10,10,9,8,4,7,6,5,4,3,3,1}; std::vector<int> v(a,a+sizeof(a)/sizeof(int)); std::for_each ( v.begin() , v.end() , (if_(_1<5)[ std::cout<
The boost::basic_format::operator % code gives an assertion since the object that is being passed is the placeholder object, and not the current value. Is there a correct way of doing this?
There is, but it is kind of complicated.
Lambda Library gets kind of hairy with more complex lambda expressions:
#include
Thanks, Haroon _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Haroon Khan
-
Jaakko Järvi