|
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)
documentation
<http://www.boost.org/doc/libs/1_49_0_beta1/libs/range/doc/html/range/reference/adaptors/introduction.html>.
Range Adaptor alternative to count_if algorithm
<http://www.boost.org/doc/libs/1_49_0_beta1/libs/range/doc/html/range/reference/adaptors/introduction.html#range.reference.adaptors.introduction.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
needed.
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.
-- Bill
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net