template< class T > class bag {\fbox{}
public: bag() { s = new list<T>; } bag(const bag<T>& b) { s = b.s; } ~bag() { delete s; } bag<T>& operator=(const bag<T>& b) { s = b.s; return *this; } virtual void insert(const T& e) { s->insert(e); } operator iter<T>() const { return *s; } int count(const T& e) const; void map(T f(const T& e)); protected: list<T>* s;see section gen-list
};
template< class T >\c{\fbox{}}
int bag<T>::count(const T& e) const { iter<T> it = *this; T* p = 0; int cnt = 0; while ( p = it() ) if ( (T&) e == *p ) cnt++;$(*)
return cnt; } template< class T >\c{\fbox{bag<T>::map
void bag<T>::map(T f(const T& e)) { iter<T> it = *this; T* p = 0; while ( p = it() ) *p = f(*p); }
template< class T >\fbox{{\tt operator<<}}
ostream& operator<<(ostream& os, const set<T>& s) { iter<T> it = s; T* p = 0; while ( p = it() ) { cout << *p << endl; } return os; }
template< class T > class power : public set<set<T> > {\c{\fbox{}}
};
sets1; s1.insert(1); s1.insert(2); set s2; s2.insert(2); s2.insert(3); cout << s1; power b; b.insert(s1); b.insert(s2); cout << (set< set >&) b; \c{// cast is necessary}