Boost logo

Boost :

Subject: Re: [boost] [range] Best way to count the elements in a filtered range?
From: Darren Garvey (darren.garvey_at_[hidden])
Date: 2013-06-19 07:06:34


On 19 June 2013 11:41, Gonzalo BG <gonzalobg88_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)
>

I think boost::size() is what you want.

size_t s = boost::size(range | filter);

See: http://www.boost.org/doc/libs/1_53_0/boost/range/size.hpp

-- 
Darren

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