// test.cc.cpp: Simple test of complete_container adaptor #include #include #include "complete_container.h" using namespace std; // Here is a (contrived) example function object type // that meets the requirements of complete_container template struct fun { void operator()(int x, AssociativeContainer& c) { cout << x << " "; if (x > 10) c.insert(x - 4); } }; // Construct a small example set or multiset of integers and // perform a complete traversal using complete_container and // an instance of fun template void example(SortedAssociativeContainer& s) { for (int j = 0; j < 7; ++j) s.insert(17*j); cout << "Original container: "; typename SortedAssociativeContainer::iterator i; for (i = s.begin(); i != s.end(); ++i) cout << " " << *i; cout << endl; cout << "Output during traversal: "; typedef complete_container cc_type; cc_type cc(s); cc_type::iterator k; fun f; for (k = cc.begin(); k != cc.end(); ++k) f(*k, cc); cout << endl; cout << "Final container: "; for (i = s.begin(); i != s.end(); ++i) cout << " " << *i; cout << endl; } int main() { cout << "Example of a complete traversal of a set container:" << endl; set s1; example(s1); cout << endl; cout << "Example of a complete traversal of a multiset container:" << endl; multiset s2; example(s2); cout << endl; return 0; }