Boost logo

Boost :

From: Robert Jones (robertgbjones_at_[hidden])
Date: 2008-07-22 08:01:11


On Tue, Jul 22, 2008 at 12:28 PM, Mathias Gaunard <
mathias.gaunard_at_[hidden]> wrote:

> Robert Jones wrote:
> > typedef pair<int, S *> Pair;
> > vector<Pair> pairs;
> > bool trueForAll = ( find_if( _1, _2, _3 ) == _2 )(
> > pairs.begin( ),
> > pairs.end( ),
> > ! bind( & S :: predOfS, bind( & Pair :: second, _1 ) ) );
> > }
> >
> > The last line gives me compile errors.
> >
> > Two things:
> > - I think I need to specicy the template parameters to find_if, but I'm
> not
> > sure quite what they are!
>
> Why are you even doing this?
> find_if(pairs.begin(), pairs.end(), your_lambda_expression) is sufficient.
>
> Otherwise, it is more practical to use a lazy function. Phoenix is
> better for that, and it actually already provides lazy versions of
> standard algorithms.
>
>
> > - The error message reckons the last arg to find_if is placeholder<4>,
> not
> > placeholder<3>, why?
>
> Because _1 is placeholder<0>.
>

Hi Mathias

I can entirely understand your horror at this code, and indeed it is highly
contrived
to be about the simplest thing I can construct which reproduces the symptoms
produced from the real code.

The essential feature, in the terms of my example code, is that I only want
to
evaluate the end( ) method once, and avoid placing it in a named variable.

It seems Phoenix may be the answer to my needs, so many thanks for that
tip.

Regards, Rob.


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