Boost logo

Boost :

Subject: Re: [boost] [Review:Algorithms] all.hpp vs std::count
From: Marshall Clow (mclow.lists_at_[hidden])
Date: 2011-10-04 18:50:56

On Oct 4, 2011, at 3:42 PM, Andrew Hundt wrote:

> What is the advantage of the functions in all.hpp over std::count?
> I feel like one could simply call (in pseudocode) std::count == 0,
> std::count == 1, std::count == class.size() to achieve the same effect.

Clarity of naming, for one.

        if ( all_of ( sequence, predicate ))
is a lot clearer than:
        if ( count_if ( sequence, value ) == sequence.count ())

Performance, for another:
        all_of ( sequence, predicate ) only examines members of the sequence until one fails.
        count_if ( sequence, value ) examines every element of the sequence.

-- Marshall

Marshall Clow Idio Software <mailto:mclow.lists_at_[hidden]>

A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait).
        -- Yu Suzuki

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