|
Boost : |
Subject: Re: [boost] [range] Best way to count the elements in a filtered range?
From: Robert Jones (robertgbjones_at_[hidden])
Date: 2013-06-19 06:52:13
On 19 June 2013 11:39, Gonzalo Brito Gadeschi <g.brito_at_[hidden]>wrote:
> I wonder what is the recommended way to count the elements in a filtered
> range.
>
> Let range be a random access range, and filter the result of
> filtered(predicate),
>
> auto filtered_range = range | filter;
> count_if( filtered_range, [](const&){ return true; }); // (& omitted in
> lambda)
>
> counts the elements in a filtered range.
>
> _If_ this is the best way to count the elements in a filtered range, what
> about defining
>
> Range boost::count(Range&& r);
>
> to count all element in the range? It could call size() if available and
> count_if otherwise.
>
> I'm not quite sure I'm understanding the question! Does
boost::count( filtered_range );
not do exactly what you want? Also, I don't understand why you'd like
am rvalue ref version of count when the argument is const, but that might
be my naivety about how to use rvalues.
- Rob.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk