Boost logo

Boost :

From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2008-07-17 11:50:16


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)


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