Boost logo

Boost Users :

From: Stefano Peluchetti (pelux_at_[hidden])
Date: 2007-08-10 06:09:49


Roman Perepelitsa <roman.perepelitsa <at> db.com> writes:

>
> Stefano Peluchetti <pelux <at> ngi.it> writes:
> > I'm actually moving everything to
> > boost::lambda::bind to
> > 1) avoid the conflict of boost::lambda::_1 and _1
> > 2) have binders that are "lambda ready" if needed
> >
> > Thank you in advance for your reply.
>
> Note that sometimes boost::bind is a better choice
> that boost::lambda::bind.
>
> 1. boost::bind has better support for smart pointers.
>
> struct A
> {
> void f() {}
> };
>
> shared_ptr<A> a;
> bind(&A::f, _1)(a); // works for boost::bind only
>
> 2. boost::bind sometimes can choose correct instance of
> overloaded function. (probably you got hit by this distinction).
>
> struct A
> {
> void f() const {}
> void f() {}
> };
>
> A a;
> bind(&A::f, a); // works for boost::bind only
>
> 3. boost::bind can accept non-const rvalue if there
> are not many arguments. I believe last (unreleased)
> version of boost::lambda::bind can do this as well.
>
> void f(int) {}
>
> bind(f, _1)(42); // works for boost::bind only
>
> My personal experience also shows that boost::bind
> based code compiles faster.
>
> Roman Perepelitsa.
>

Very interesting information, thank you.
Is there any documentation about these details ?
I couldn't find anything like that in the boost lambda library documentation.

I noticed that boost::bind code usually compiles faster too. But I'm working an
a numerical simulation library and I have to compose functions together a lot of
times. That's where lambda is very handy.

Also I can't still understand *why* only the boost::bind binder works in the
three examples you gave. What is the technical reason behind these results? Is
it really necessary to study the whole boost::lambda library from source code to
figure it out?

Best Regards


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