#ifndef SEQ_H_ #define SEQ_H_ 1 // Code from ftp://ftp.aw.com/cp/koenig/code.tar.Z // in conjunction with the book \emph{Ruminations on C++}. /* *********************************************** Copyright, 1997 AT&T Corporation. All rights reserved. Permission is granted for individuals to use this material for educational purposes in connection with the book Ruminations on C++, Addison-Wesley, 1997, ISBN 0-201-42339-1. ************************************************** */ // added by Oldham 2000Jan15; fixes the friend-template problem. // Apparently, the C++ standard changed since Stroustrup's third edition. template class Seq; template int operator==(const Seq&, const Seq&); template class Seq_item { friend class Seq; int use; const T data; Seq_item* next; Seq_item(const T& t, Seq_item* s); Seq_item(const T& t): use(1), data(t), next(0) { } }; template class Seq { friend int operator==<>(const Seq&, const Seq&); public: Seq(): item(0), len(0) { } Seq(const T& t, const Seq& x): item(new Seq_item(t, x.item)), len(x.len+1) { } Seq(const Seq& s): item(s.item), len(s.len) { if (item) item->use++; } Seq(Seq_item* s, unsigned l): item(s), len(l) { if (s) s->use++; } ~Seq() { destroy(item); } Seq& operator=(const Seq&); T hd() const; Seq tl() const; //operator int() const { return item != 0; } operator bool() const { return item; } bool empty(void) const { return !item; } // added by Oldham 2000Jan15 void destroy(Seq_item*); Seq& operator++(); Seq operator++(int); T operator*() { return hd(); } Seq& insert(const T&); Seq_item* owntail(); Seq& flip(); unsigned length() const { return len; } // added by Oldham 2000Feb16 private: Seq_item* item; unsigned len; }; template Seq cons(const T& t, const Seq& s); #include "seq.cpp" // added by Oldham 2000Jan15 #endif // SEQ_H_