Compare
functional parameter determines sorting order
Compare(v1, v2)
, Compare(v2, v1)
, or
v2 == v1
must be true for any v1
and v2
- tricotomy
<
is acceptable, <=
is not
<
find()
includes(b1, e1, b2, e2)
returns true if and only if every
value in the iterator range (b2, e2)
is also in the iterator
range (b1, e1)
- the subset predicate
set_union(b1, e1, b2, e2, i)
stores into the container
referenced by iterator i
the values that appear either in
iterator range (b1, e1)
or iterator range (b2, e2)
set_intersection(b1, e1, b2, e2, i)
stores into the container
referenced by iterator i
the values that appear both in
iterator range (b1, e1)
and iterator range (b2, e2)
set_difference(b1, e1, b2, e2, i)
stores into the container
referenced by iterator i
the values that appear in
iterator range (b1, e1)
but not in iterator range (b2, e2)
set_symmetric_difference(b1, e1, b2, e2, i)
stores into the
container
referenced by iterator i
the values that appear in either
iterator range (b1, e1)
or iterator range (b2, e2)
but not in both
accumulate(b, e, v, f)
b,e
, compute the value
f(...f(f(v, v1), v2), ..., vn)
f
defaults to plus, computing
v + v1 + v2 + ... + vn
#include <string> #include <vector> #include <numeric> static string concat(const string str1, const string str2) { return str1 + (str1.length() == 0 ? "" : " ") + str2; } int main(void) { string words[] = {"time", "flies", "like", "an", "arrow"}; vector<string> wordv(words, words + 5); cout << accumulate(wordv.begin(), wordv.end(), string(""), concat) << "\n"; return 0; }
partial_sum(b, e, v, f)
adjacent_difference(b, e, i, f)
inner_product(b1, e1, b2, v, f1, f2)
(b1, e1)
be represented by the sequence
of values v1, v2, ..., vn
f(...f(f(v, v1), v2), ..., vn)
(b1, e1)
be represented by the sequence
of values v1, v2, ..., vn
f(...f(f(v, v1), v2), ..., vn)
f
defaults to plus, computing
v + v1 + v2 + ... + vn
#include <string> #include <numeric> #include <list> typedef pair<string, int> grade; static grade pair_them(string & s, int i) { return grade(s, i); } static list<grade> append_them(list<grade> l, grade g) { l.push_back(g); return l; } int main(void) { string names[] = {"clinton", "bush", "regan", "carter"}; int numbers[] = {11, 12, 13, 14}; list<grade> roster; roster = inner_product(names, names + 4, numbers, roster, append_them, pair_them); for (list<grade>::iterator i = roster.begin(); i != roster.end(); i++) cout << (*i).first << " " << (*i).second << "\n"; return 0; }
This page last modified on 21 July 2000.