<) is a binary predicate
!) is a unary predicate
generate(s, e, f)
for (i = s; i < e; i++) *i = f()
generate(v.begin(), v.end(), random)
sort(s, e, f)
f is an optional predicate parameter that determines if the
first argument is less than the second argument
sort() actually takes a Comparison, which is a binary
predicate with special properties
<) and greater-than (>) are Comparisons
<=) and at-least (>=) are not Comparisons
plus<T>, minus<T>
equal_to<T>, greater_than<T>
and<T>
T must define the associated operator
#include <vector>
#include <numeric>
#include <functional>
#include <stdlib.h>
class test {
public:
test operator+(const test & t) const {
return *this;
}
};
int main(void) {
vector<test> iv(10);
accumulate(iv.begin(), iv.end(), test(), plus<test>());
return 0;
}
copy(d1.begin(), d1.end(), d2.begin()); reverse(d2.begin(),
d2.end())
_copy as the last part of their
name
reverse_copy(d1.begin(), d1.end(), d2.begin())
unique() is as expensive as copying, so unique_copy()
is available for use
random_shuffle() is about as expensive as
copying, but there is no random_shuffle_copy()
remove(s, e, v) - remove all occurrences of the value
v from the iterator range (s, e)
remove(s, e, f) - remove all occurrences of the value
v from the iterator range (s, e) where f(v) is true
_if naming convention comes to the rescue
_if use the value parameter as a
function
remove_if(s, e, f)
replace(s, e, v1, v2) - replace all occurrences of
the value v1 in the iterator range (s, e) with the
value v2
replace_if(s, e, f, v) - replace all values v in the
iterator range (s, e) with the value v2 when f(v)
is true
This page last modified on 27 June 2000.