Boost logo

Boost Users :

Subject: [Boost-users] [range] count vs count_if
From: Bill Buklis (boostusr_at_[hidden])
Date: 2012-02-09 16:08:20

The documentation for boost range states that count_if can be expressed
as count using a filtered adaptor and then goes on to say that no
algorithm needs the _if suffix. I'm having trouble seeing how that is
the case. Here is the relevant section from the latest (1.49 beta)

                Range Adaptor alternative to count_if algorithm

    boost::count_if( rng, pred );

    can be expressed as

    boost::count( rng | boost::adaptors::filtered(pred), out );

    What this means is that /*no*/ algorithm with the |_if| suffix is

First of all, what is "out"? I think this is supposed to be "value" as
count requires the value to compare against for the count. But, since it
does require the value, this makes the function fundamentally different
than count_if which will only count the values that match the predicate.
As far as I can tell, this means that "count" will filter values both by
the predicate and by the value.

What am I missing? How can count_if be properly expressed as count. To
me it seems like it can't.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at