Rogue Wave banner
Previous fileTop of DocumentContentsIndexNext file

3.2 Predicates

A predicate is simply a function that returns either a boolean value or an integer value. Following the normal C convention, an integer value is assumed to be true if non-zero, and false otherwise. Here is an example of a predicate, which takes an integer as argument and returns true if the number represents a leap year, and false otherwise:

A predicate is used as an argument, for example, in the generic algorithm named find_if(). This algorithm returns the first value that satisfies the predicate, returning the end-of-range value if no such element is found. Using this algorithm, the following locates the first leap year in a list of years:


Previous fileTop of DocumentContentsIndexNext file

OEM Edition, ©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.