STL Algorithm In One Container

Asked By 10 points N/A Posted on -
qa-featured

I need an STL algorithm that uses a predicate and a collection and returns true if only one member of the collection satisfies the predicate, otherwise returns false.How could I do that with STL algorithms?

SHARE
Answered By 0 points N/A #318448

STL Algorithm In One Container

qa-featured

I can think of two things: std :: count_if and compare the result with 1.

To avoid traversing the entire container, for example, if the first two elements already match the predicate, I would use two calls to search for matching items.

Login/Register to Answer

Related Questions