I'm kind of loosing faith that this list ever responds to questions
but here goes anyway.
I've narrowed a problem down to this:
#include <iostream>
#include
Hello Noah,
----- Mensaje original -----
De: Noah Roberts
I'm kind of loosing faith that this list ever responds to questions but here goes anyway.
I've narrowed a problem down to this:
[...]
std::cerr << "Value: " << (l::bind(&test_b::f, l::_1))(td) << "\n"; [...] Compiler result: cannot instantiate abstract class test_b.
I haven't been following your investigations into the Boost
Lambda Library so excuse me if he following is not relevant:
your example can be made to work by using boost::reference_wrappers:
#include <iostream>
#include
On 11/29/06, "JOAQUIN LOPEZ MU?Z"
std::cerr << "Value: " << (l::bind(&test_b::f, l::_1))(boost::ref(td)) << "\n";
Well, I tried putting ref on the other side but this works...my way didn't.
Now I would need to find how to use this solution for my original
problem when td is actually a shared_ptr to an abstract base:
boost::shared_ptr
Noah Roberts ha escrito: [...]
So in the end, my problem is thus:
std::find_if(cont.begin(), cont.end(), bind(&deref_val_type::f, _1) == 5);
How is that accomplished with lambda if cont holds smart pointers? So far I haven't found any way...
OK, you can write it with Boost Lambda as follows: namespace l = boost::lambda; std::find_if( cont.begin(), cont.end(), l::bind<int>(&*l::_1->*&deref_val_type::f)==5); Boost.Bind is smarter here, since Boost Lambda needs assistance in: 1. Determining the return type of deref_val_type::f (hence the <int> in l::bind<int>.) 2. Dereferencing the shared_ptr, hence the use of &*l::_1 to get a plain pointer from the shared_ptr, combined with ->* to call deref_val_type::f Others might find terser ways to express this with Boost Lambda, but looks like Boost.Bind is a clear winner here. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Joaquín Mª López Muñoz wrote:
Noah Roberts ha escrito:
[...]
So in the end, my problem is thus:
std::find_if(cont.begin(), cont.end(), bind(&deref_val_type::f, _1) == 5);
How is that accomplished with lambda if cont holds smart pointers? So far I haven't found any way...
OK, you can write it with Boost Lambda as follows:
namespace l = boost::lambda;
std::find_if( cont.begin(), cont.end(), l::bind<int>(&*l::_1->*&deref_val_type::f)==5);
bind( &deref_val_type::f, *_1 ) == 5 may work with Lambda. I remember patching it so that *_1 works for shared_ptr. I looked into making lambda::bind( &deref_val_type::f, _1 ) work but got lost in the source and gave up. :-) There's always the less elegant lambda::bind( mem_fn( &deref_val_type::f ), _1 ) approach, of course.
Peter Dimov ha escrito:
Joaquín Mª López Muñoz wrote:
Noah Roberts ha escrito:
[...]
So in the end, my problem is thus:
std::find_if(cont.begin(), cont.end(), bind(&deref_val_type::f, _1) == 5);
How is that accomplished with lambda if cont holds smart pointers? So far I haven't found any way...
OK, you can write it with Boost Lambda as follows:
namespace l = boost::lambda;
std::find_if( cont.begin(), cont.end(), l::bind<int>(&*l::_1->*&deref_val_type::f)==5);
bind( &deref_val_type::f, *_1 ) == 5 may work with Lambda.
Almost: the translation of the expression to the lambda world, i.e.
l::bind( &deref_val_type::f, *l::_1 ) == 5
(assuming namespace l = boost::lambda) fails to compile because
it indices the declaration of
boost::tuples::cons
On 11/30/06, Joaquín Mª López Muñoz
bind( &deref_val_type::f, *_1 ) == 5 may work with Lambda.
Almost: the translation of the expression to the lambda world, i.e.
l::bind( &deref_val_type::f, *l::_1 ) == 5
(assuming namespace l = boost::lambda) fails to compile because it indices the declaration of
boost::tuples::cons
::head which is not instantiable deref_val_type is abstract.
Right, works fine until working with abstract types. Kind of frustrating to toss it into a test with mock objects and not realize you also need to test that your algorithms work with abstract interfaces. The closest I
can get in BLL to your formulation is:
l::bind( &deref_val_type::f, &*l::_1 ) == 5
which works as expected.
Yep, that works. Not exactly what I wanted to see, and I should have thought of it, but there it is. I think this is something the lambda folks might want to work on as it isn't exactly favorable (is it in the works?). Bind is a lot easier to work with because it catches on.
On Nov 30, 2006, at 11:38 AM, Noah Roberts wrote:
On 11/30/06, Joaquín Mª López Muñoz
wrote: bind( &deref_val_type::f, *_1 ) == 5 may work with Lambda.
Almost: the translation of the expression to the lambda world, i.e.
l::bind( &deref_val_type::f, *l::_1 ) == 5
(assuming namespace l = boost::lambda) fails to compile because it indices the declaration of
boost::tuples::cons
::head which is not instantiable deref_val_type is abstract.
Right, works fine until working with abstract types. Kind of frustrating to toss it into a test with mock objects and not realize you also need to test that your algorithms work with abstract interfaces.
The closest I
can get in BLL to your formulation is:
l::bind( &deref_val_type::f, &*l::_1 ) == 5
which works as expected.
Yep, that works. Not exactly what I wanted to see, and I should have thought of it, but there it is. I think this is something the lambda folks might want to work on as it isn't exactly favorable (is it in the works?).
On the list... needs a non-trivial amount of changes Jaakko
Bind is a lot easier to work with because it catches on. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (5)
-
"JOAQUIN LOPEZ MU?Z"
-
Jaakko Jarvi
-
Joaquín Mª López Muñoz
-
Noah Roberts
-
Peter Dimov