[Home]STLAlgorithmExtensions/ExistsAndOnlyAlgorithm

BOOST WIKI | STLAlgorithmExtensions | RecentChanges | Preferences | Page List | Links List

Difference (from prior major revision) (minor diff, author diff)

Changed: 34c34,41
-- People/Vladimir Prus
-- People/Vladimir Prus

<hrule>

I don't think you need an extra algorithm to perform what count(...)==1 (or count(...)==count) already does with
the same complexity (in particular, the same number of calls to operator== or to pred).

-- [Herve Bronnimann]

This algorithm completes the set of basic predicates on sequences.
    
template<class Container, class Predicate>
        inline bool
        exists_and_only(const Container& cont, Predicate pred)
        {
            typename Container::iterator i = find_if(cont, pred);
            if (i == cont.end()) return false;
            if (find_if(++i, cont.end(), pred) != cont.end()) return false;
            return true;
        }

-- People/Vladimir Prus


Why is this a container and not an iterator range?

Could this be more generic by passing in the number of occurances?

    
template<typename InputIterator, typename T>
        inline bool
        exact_count(InputIterator first, InputIterator last, T const&, int count = 1);

template<typename InputIterator, typename Predicate>
        inline bool
        exact_count_if(InputIterator first, InputIterator last, Predicate pred, int count = 1);

This is container because it's the way I use it. I still hope we'll agree on how to implement container algorithm and the algorithm's idea is independent from interface. I have some objections to exact_count: -- People/Vladimir Prus

<hrule>

I don't think you need an extra algorithm to perform what count(...)==1 (or count(...)==count) already does with the same complexity (in particular, the same number of calls to operator== or to pred).

-- [Herve Bronnimann]


BOOST WIKI | STLAlgorithmExtensions | RecentChanges | Preferences | Page List | Links List
Edit text of this page | View other revisions
Last edited August 31, 2004 8:24 am (diff)
Search:
Disclaimer: This site not officially maintained by Boost Developers