[Univ of Cambridge] [Dept of Engineering]
next up previous contents
Next: Adapters Up: Predicates Previous: Predicates

Creating predicates

<functional> supplies common conditions that can operate on various types: e.g., greater_equal<int>(), plus<double>(), logical_or<int>() etc. The following does a vector multiplication of a and b, putting the answer in res to which elements are added one at a time.

void discount(vector<double>& a, vector<double>& b, vector<double>& res)
{
transform(a.begin(), a.end(), b.begin(), back_inserter(res), multiplies<double>());
// vector multiplication
}



Tim Love
2001-07-05