2
/******************************************************************************
4
* DESCRIPTION: linked lists with reference counting
5
* COPYRIGHT : (C) 1999 Joris van der Hoeven
6
*******************************************************************************
7
* This software falls under the GNU general public license and comes WITHOUT
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
11
******************************************************************************/
18
template<class T> class list_rep;
19
template<class T> class list;
21
template<class T> bool nil (list<T> l);
22
template<class T> bool atom (list<T> l);
23
template<class T> bool strong_equal (list<T> l1, list<T> l2);
25
template<class T> class list {
26
CONCRETE_NULL_TEMPLATE(list,T);
28
inline list (T item, list<T> next);
29
inline list (T item1, T item2, list<T> next);
30
inline list (T item1, T item2, T item3, list<T> next);
31
T& operator [] (int i);
35
friend bool atom LESSGTR (list<T> l);
36
friend bool strong_equal LESSGTR (list<T> l1, list<T> l2);
39
extern int list_count;
40
template<class T> class list_rep: concrete_struct {
45
inline list_rep<T> (T item2, list<T> next2): item(item2), next(next2) {
46
DEBUG(list_count++); }
47
inline ~list_rep<T> () { DEBUG(list_count--); }
51
CONCRETE_NULL_TEMPLATE_CODE(list,class,T);
52
#define TMPL template<class T>
53
TMPL inline list<T>::list (T item): rep (new list_rep<T>(item, list<T> ())) {}
54
TMPL inline list<T>::list (T item, list<T> next):
55
rep (new list_rep<T>(item, next)) {}
56
TMPL inline list<T>::list (T item1, T item2, list<T> next):
57
rep (new list_rep<T>(item1, list<T> (item2, next))) {}
58
TMPL inline list<T>::list (T item1, T item2, T item3, list<T> next):
59
rep (new list_rep<T>(item1, list<T> (item2, item3, next))) {}
60
TMPL inline bool atom (list<T> l) { return (!nil (l)) && nil (l->next); }
61
TMPL list<T> list<T>::init= list<T> ();
63
TMPL int N (list<T> l);
64
TMPL list<T> copy (list<T> l);
65
TMPL list<T> operator * (list<T> l1, T x);
66
TMPL list<T> operator * (list<T> l1, list<T> l2);
67
TMPL list<T> head (list<T> l, int n=1);
68
TMPL list<T> tail (list<T> l, int n=1);
69
TMPL T last_item (list<T> l);
70
TMPL T& access_last (list<T>& l);
71
TMPL list<T>& suppress_last (list<T>& l);
72
TMPL list<T> reverse (list<T> l);
73
TMPL list<T> remove (list<T> l, T what);
75
TMPL ostream& operator << (ostream& out, list<T> l);
76
TMPL list<T>& operator << (list<T>& l, T item);
77
TMPL list<T>& operator << (list<T>& l1, list<T> l2);
78
TMPL list<T>& operator >> (T item, list<T>& l);
79
TMPL list<T>& operator << (T& item, list<T>& l);
80
TMPL bool operator == (list<T> l1, list<T> l2);
81
TMPL bool operator != (list<T> l1, list<T> l2);
82
TMPL bool operator < (list<T> l1, list<T> l2);
83
TMPL bool operator <= (list<T> l1, list<T> l2);
88
#endif // defined LIST_H