-- 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; }

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:

- exact_count(v.begin(), v.end(), some_value) is not intuitively clear expression, I think
- I'm not sure count!=1 is of any use.

<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]

Disclaimer: This site not officially maintained by Boost Developers