Boost logo

Boost :

Subject: Re: [boost] [range] Best way to count the elements in a filtered range?
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2013-06-19 11:03:14


Hi Gonzalo,

Gonzalo Brito Gadeschi wrote:

> Someone suggested to use boost::size in the other thread, but size does
>
> boost::end(rng) - boost::begin(rng)
>
> which is not the number of elements in the filtered range.
>

Try boost::distance(rng | filtered(pred)). Size shouldn't even compile,
since it requires random access, and a filtered range cannot be random
access.

HTH,
Nate


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