Boost logo

Boost :

From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-07-17 15:47:32


On Thu, Jul 17, 2008 at 4:50 PM, Andrey Semashev <andrey.semashev_at_[hidden]>
wrote:

> Robert Jones wrote:
>
>> Given a bit of code like this,
>>
>> struct S
>> {
>> bool pred( ) const;
>> };
>>
>> typdef vector<pair<string, S *> > V;
>> V :: const_iterator i;
>>
>> i -> second -> pred( );
>>
>> I'd like to rewrite the last line as a lambda expression. Looking at the
>> documentation, I think this is done with
>>
>> bind( & S :: pred, bind( & V :: value_type :: second, _1 ) )( * i );
>>
>> which works. But I'd rather be writing something like
>>
>> ( _1 -> second -> pred )( * i );
>>
>> Am I right in thinking that Boost.Lambda just doesn't work like this, and
>> the frst form is how it's done?
>>
>
> It doesn't work because Lambda's operator-> won't be able to provide second
> or pred in its result.
>
> You can do this, however:
>
> typedef V::value_type VT;
>
> bind(&S::pred, &_1->*&VT::second)
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>

Ah... that 's getting there! And so presumably by extension I can write

& ( & _1 ->* & V :: value_type :: second ) ->* & S :: pred;

or is that a step too far?

-- 
ACCU - Professionalism in programming - http://www.accu.org

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk