|
Boost Users : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2006-11-30 10:59:43
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.
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