Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-04-14 18:24:26


Joel de Guzman wrote:
>
> ----- Original Message -----
> From: "Aleksey Gurtovoy" :
> >
> > Is this one better?
> >
> > template<
> > typename Sequence
> > , typename Predicate
> > >
> > struct count_if
> > {
> > typedef typename fold<
> > Sequence
> > , integral_c<unsigned long, 0>
> > , select_if< apply<Predicate,_2>, next<_1>, _1 >
> > >::type type;
> > };
>
> I like this one a lot, Aleksey! It looks a lot like the fold that I
> am accustomed to. In fact I was almost about to post something
> like this but hesitated. Can we do it this way?

Yes, the above is a perfectly working implementation of 'count_if' - on a
reasonably conforming compiler.

> If so, why did we bother with the long one?

It's how the algorithm implemented by the library itself.

> What's the advantage of the first over this?

"The long" version is more portable (lambda facility requires partial
specialization and template template parameters), and it taxes the compiler
a little bit more.

Aleksey


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