Chapter 3. Predicates, Part 2: Matters of State

Difficulty: 7

Following up from the introduction given in Item 2, we now examine “stateful” predicates. What are they? When are they useful? How compatible are they with standard containers and algorithms?

  1. What are predicates, and how are they used in STL? Give an example.

  2. When would a “stateful” predicate be useful? Give examples.

  3. What requirements on algorithms are necessary in order to make stateful predicates work correctly?

Solution

Solution

Unary and Binary Predicates

  • 1. What are predicates, and how are they used in STL?

A predicate is a pointer to a function, or a function object (an object that supplies the ...

Get More Exceptional C++ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.