Boost logo

Boost :

Subject: Re: [boost] [range] Best way to count the elements in a filtered range?
From: Jonathan Wakely (jwakely.boost_at_[hidden])
Date: 2013-06-19 07:02:03

On 19 June 2013 11:52, Robert Jones wrote:
>> _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.

If Range is a template parameter then Range&& can also bind to
lvalues, and Range will be deduced as an lvalue-reference type such as

The signature above would therefore return an rvalue when passed an
rvalue, and return an lvalue when passed an lvalue. I'm not sure how
it would return the number that it's supposed to be counting though,
I'd have expected it to return the range's difference type, and in
that case it might as well be count(const Range&), or count(const
Range&, const Value&) like the existing range algorithm.

Boost list run by bdawes at, gregod at, cpdaniel at, john at