Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) Predicate

 

A predicate is a logical expression that evaluates to true or false, like in if-statements.

 

 

 

 

 

Example

 

In the example below, it is shown how to replace negative values by zero. The predicate is if an integer is less then zero.

 

#include <algorithm>
#include <numeric>
#include <vector>

void ReplaceNegativeByZero(std::vector<int>& v)
{
  std::replace_if(v.begin(),v.end(),
    std::bind2nd(std::less<int>(),0),0);
}

 

 

 

 

 

STL predicates

 

An overview of STL predicates names and their corresponding operator, from [0]. These predicates can be found in the header file functional.

 

 

 

 

 

 

My predicates

 

 

 

 

 

 

References

 

    Bjarne Stroustrup. The C++ Programming Language (3rd edition). 1997. ISBN: 0-201-88954-4. Chapter 18.4.2.1 : 'Overview of Predicates'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict