Boost logo

Boost :

Subject: [boost] [range] Best way to count the elements in a filtered range?
From: Gonzalo BG (gonzalobg88_at_[hidden])
Date: 2013-06-19 06:41:17


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.

Bests,
Gonzalo BG


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk