On 19 June 2013 11:39, Gonzalo Brito Gadeschi
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.