Code Fragment: Merger1



template <typename Object, typename Sequence>
class Merger {						// generic Merger
protected: 						// local types
  typedef typename Sequence::ObjectIterator ObjectIterator;
private: 						// member data
  ObjectIterator iterA, iterB;				// iterators for A and B
  Object a, b; 	                			// current objects
public:
  Merger() { }						// constructor
							// generic merge function
  void merger(const Sequence& A, const Sequence& B, Sequence& C);
protected: 						// overridden functions
  virtual void aIsLess(const Object& a, Sequence& C) = 0;
  virtual void bothEqual(const Object& a, const Object& b, Sequence& C) = 0;
  virtual void bIsLess(const Object& b, Sequence& C) = 0;
protected: 						// local utilitites
  bool getFromA() {					// get next from A
    if (iterA.hasNext()) { a = iterA.next(); return true; }
    return false;
  }
  bool getFromB() {					// get next from B
    if (iterB.hasNext()) { b = iterB.next(); return true; }
    return false;
  }  
};