return 0;
}
bcompos1.cpp
#include ‹iostream.h›
#include ‹stl.h›
struct odd: public unary_function‹int, bool› {
odd() {}
bool operator() (int n_) const {return (n_ % 2) - 1;}
};
struct positive: public unary_function‹int, bool› {
positive() {}
bool operator() (int n_) const {return n_ ›= 0;}
};
int array[6] = {-2, -1, 0, 1, 2, 3};
int main() {
binary_compose‹logical_and‹bool›, odd, positive› b(logical_and‹bool›(), odd(), positive ());
int* p = find_if(array, array + 6, b);
if (p != array + 6) cout ‹‹ *p ‹‹ ' is odd and positive' ‹‹ endl;
return 0;
}
setsymd2.cpp
#include ‹stl.h›
#include ‹iostream.h›
#include ‹string.h›
char* word1 = 'ABCDEFGHIJKLMNO';
char* word2 = 'LMNOPQRSTUVWXYZ';
int main() {
ostream_iterator‹char› iter(cout, ' ');
cout ‹‹ 'word1: ';
copy(word1, word1 + ::strlen(word1), iter);
cout ‹‹ '
word2: ';
copy(word2, word2 + ::strlen(word2), iter);
cout ‹‹ endl;
set_symmetric_difference(word1, word1 + ::strlen(word1), word2, word2 + ::strlen(word2), iter, less‹char›());
cout ‹‹ endl;
return 0;
}
search0.cpp
#include ‹stl.h›
#include ‹iostream.h›
int v1[6] = {1, 1, 2, 3, 5, 8};
int v2[6] = {0, 1, 2, 3, 4, 5};
int v3[2] = {3, 4};
int main() {
int* location;
location = search(v1, v1 + 6, v3, v3 + 2);
if (location == v1 + 6) cout ‹‹ 'v3 not contained in v1' ‹‹ endl;
else cout ‹‹ 'Found v3 in v1 at offset: ' ‹‹ location - v1 ‹‹ endl;
location = search(v2, v2 + 6, v3, v3 + 2);
if (location == v2 + 6) cout ‹‹ 'v3 not contained in v2' ‹‹ endl;
else cout ‹‹ 'Found v3 in v2 at offset: ' ‹‹ location - v2 ‹‹ endl;
return 0;
}
eqlrnge1.cpp
#include ‹stl.h›
#include ‹iostream.h›
int main() {
typedef vector‹int› IntVec;
IntVec v(10);
for (int i = 0; i ‹ v.size(); i++) v[i] = i / 3; ostream_iterator‹int› iter(cout, ' ');
cout ‹‹ 'Within the collection:
';
copy(v.begin(), v.end(), iter);
pair‹IntVec::iterator, IntVec::iterator› range;
range = equal_range(v.begin(), v.end(), 2);
cout ‹‹ '
2 can be inserted from before index ' ‹‹ (range.first - v.begin())
‹‹ ' to before index ' ‹‹ (range.second - v.begin()) ‹‹ endl;
return 0;
}
rotcopy1.cpp