find()
random_shuffle()
vp = find(start, end, v) - search the container delimited by
start and end for the value v; return a reference to the
value in the container if found, or else return end
char str1[13] = "Hello World!"; char *cp = find(&str1[0], &str1[12], 'o'); cout << (cp == &str1[12] ? "didn't find it.\n" : "found it.\n"); cp = find(&str1[0], &str1[12], 'x'); cout << (cp == &str1[12] ? "didn't find it.\n" : "found it.\n");
sp = search(start1, end1, start2, end2) - search the container
delimited by start1 and end1 for the contents of the
container delimited by start2 and end2; return a reference to
the start of the match if found, or else return end1
char str1[13] = "Hello World!"; char pat[4] = "o W"; char *cp = search(&str1[0], &str1[12], &pat[0], &pat[3]); cout << (cp == &str1[12] ? "didn't find it.\n" : "found it.\n"); pat[2] = 'w'; cp = search(&str1[0], &str1[12], &pat[0], &pat[3]); cout << (cp == &str1[12] ? "didn't find it.\n" : "found it.\n");
copy(start1, end1, start2) - copy the contents of the container
delimited by start1 and end1 to the container location start2
char str1[13] = "Hello World!"; char str2[13]; copy(&str1[0], &str1[12], &str2[0]); cout << "str1 = " << str1 << ", str2 = " << str2 << ".\n";
random_shuffle(start, end) - randomly shuffle the contents of the
container delimited by start and end
char str[13] = "Hello World!"; cout << "str = \"" << str; random_shuffle(&str[0], &str[12]); cout << "\", str shuffled = \"" << str << "\".\n";
sort(start, end) - sort the contents of the container delimited by
start and end in ascending order by <
char str[13] = "Hello World!"; cout << "str = \"" << str; sort(&str[0], &str[12]); cout << "\", str sorted = \"" << str << "\".\n";
end3 = set_union(start1, end1, start2, end2, start3) - form the
set union of the contents of the container delimited by start1 and
end1) and the contents of the container delimited by start2 and
end2; store the union in the container starting at start3,
and return a reference to the end of the union
char a[] = "12a"; char b[] = "abc"; char c[7]; char *end = set_union(&a[0], &a[3], &b[0], &b[3], &c[0]); *end = 0; cout << "the union of " << a << " and " << b << " is " << c << ".\n";
v = accumulate(start, end, i) - compute the sum of the container
contents delimited by start and end, using i as the
initial value of the sum; return the sum
int ivals[] = {1, 2, 3};
int sum = accumulate(&ivals[0], &ivals[3], 0);
cout << "the sum is " << sum << ".\n";
This page last modified on 7 June 2000.