1 // GROUPS passed templates nested-classes
2 // Special g++ Options:
4 // The SetLS template test
6 // Wendell Baker, Berkeley CAD Group, 1993 (wbaker@ic.Berkeley.EDU)
10 #pragma implementation "ListS.h"
11 #pragma implementation "SetLS.h"
15 # 1 "../../templates/SetLS.h" 1
21 // A Set Template - implemented with an ListS
23 // Wendell Baker, Berkeley CAD Group, 1993 (wbaker@ic.Berkeley.EDU)
33 // $Source: /egcs/carton/cvsfiles/egcs/gcc/testsuite/g++.old-deja/g++.jason/2371.C,v $
36 // $Date: 1997/08/19 07:35:23 $
43 # 37 "../../templates/SetLS.h"
46 # 1 "../../templates/ListS.h" 1
52 // A List Template - providing a singly linked capability
54 // Wendell Baker, Berkeley CAD Group, 1993 (wbaker@ic.Berkeley.EDU)
64 // $Source: /egcs/carton/cvsfiles/egcs/gcc/testsuite/g++.old-deja/g++.jason/2371.C,v $
67 // $Date: 1997/08/19 07:35:23 $
72 # 1 "/projects/gnu-cygnus/gnu-cygnus-14/mips/lib/gcc-lib/decstation/cygnus-reno-1/g++-include/bool.h" 1 3
73 // Defining XTRUE and XFALSE is usually a Bad Idea,
74 // because you will probably be inconsistent with anyone
75 // else who had the same clever idea.
76 // Therefore: DON'T USE THIS FILE.
86 # 26 "../../templates/ListS.h" 2
88 # 37 "../../templates/ListS.h"
92 // g++ reno-1 is not yet capable of creating templates with nested
93 // classes which instantiate the template arguments.
99 ListS_link(const T& i, ListS_link<T> *n = 0): item(i), next(n)
105 // For now, errors are raised by ::abort() because exceptions
106 // are not well implemented in cxx or at all in CC 3.0.1
112 ListS(const ListS<T>&);
115 void operator=(const ListS<T>&);
117 unsigned length() const
120 void prepend(const T& item);
121 void append(const T& item);
124 const T& head() const
126 return head_link->item; }
129 return head_link->item; }
130 void head(T& fill) const
132 fill = head_link->item; }
134 { remove_head_filling(0); }
135 void remove_head(T& fill)
136 { remove_head_filling(&fill); }
138 const T& tail() const
140 return tail_link->item; }
143 return tail_link->item; }
144 void tail(T& fill) const
146 fill = tail_link->item; }
150 Vix(): owner(0), index(0)
153 // These are friend functions so that v == x is the same as x == v
154 friend int operator==(void *v, const Vix& x)
155 { return v == x.index; }
156 friend int operator==(const Vix& x, void *v)
157 { return v == x.index; }
158 friend int operator!=(void *v, const Vix& x)
159 { return v != x.index; }
160 friend int operator!=(const Vix& x, void *v)
161 { return v != x.index; }
162 friend int operator==(const Vix& x1, const Vix& x2)
163 { return x1.owner == x2.owner && x1.index == x2.index; }
164 friend int operator!=(const Vix& x1, const Vix& x2)
165 { return x1.owner != x2.owner || x1.index != x2.index; }
167 friend class ListS<T>;
170 Vix(const ListS<T> *o, ListS_link<T> *i): owner(o), index(i)
177 const ListS<T> *owner;
179 ListS_link<T> *index;
186 { return Vix(this, head_link); }
187 void next(Vix& x) const
190 x.index = x.index->next; }
191 T& operator()(const Vix& x)
193 return x.index->item; }
194 const T& operator()(const Vix& x) const
196 return x.index->item; }
198 # 154 "../../templates/ListS.h"
203 ListS_link<T> *head_link; // 0 for a zero-length list
204 ListS_link<T> *tail_link; // 0 for a zero-length list
211 // fill may be 0 (then don't fill)
212 void remove_head_filling(T *fill);
214 void ensure_1() const
215 { if (0 == head_link)
217 void check(const Vix& x) const
218 { if (this != x.owner)
232 ListS<T>::ListS(const ListS<T>& other):
237 for (Vix x=other.first(); 0 != x; other.next(x))
249 ListS<T>::operator=(const ListS<T>& other)
252 for (Vix x=other.first(); 0 != x; other.next(x))
258 ListS<T>::prepend(const T& item)
261 head_link = new ListS_link<T>(item, head_link);
266 tail_link = head_link;
272 ListS<T>::append(const T& item)
275 ListS_link<T> *new_link = new ListS_link<T>(item);
279 if (0 == tail_link) {
280 head_link = new_link;
281 tail_link = new_link;
283 tail_link->next = new_link;
284 tail_link = tail_link->next;
294 ListS_link<T> *next, *l;
298 for (l=head_link; 0 != l; l=next) {
310 ListS<T>::remove_head_filling(T* fill)
311 // fill may be 0 in which case don't assign into it
315 ListS_link<T> *ohead = head_link;
321 head_link = ohead->next;
329 # 39 "../../templates/SetLS.h" 2
332 # 62 "../../templates/SetLS.h"
339 void add(const T& item);
340 // There is no remove(const T& item) for this set
341 bool contains(const T& item) const;
343 unsigned length() const
344 { return list.length(); }
351 Vix(): owner(0), vix()
354 // These are friend functions so that v == x is the same as x == v
355 friend int operator==(void *v, const Vix& x)
356 { return v == x.vix; }
357 friend int operator==(const Vix& x, void *v)
358 { return v == x.vix; }
359 friend int operator!=(void *v, const Vix& x)
360 { return v != x.vix; }
361 friend int operator!=(const Vix& x, void *v)
362 { return v != x.vix; }
363 friend int operator==(const Vix& x1, const Vix& x2)
364 { return x1.owner == x2.owner && x1.vix == x2.vix; }
365 friend int operator!=(const Vix& x1, const Vix& x2)
366 { return x1.owner != x2.owner || x1.vix != x2.vix; }
368 friend class SetLS<T>;
370 Vix(const SetLS<T> *o, const ListS<T>::Vix& x): owner(o), vix(x)
373 const SetLS<T> *owner;
379 { return Vix(this, list.first()); }
380 void next(Vix& x) const
383 const T& operator()(const Vix& x) const
385 return list(x.vix); }
386 // There is item no remove(const Vix&) for this set
391 void check(const Vix& x) const
392 { if (this != x.owner)
408 SetLS<T>::add(const T& item)
410 if ( ! contains(item) ) {
421 SetLS<T>::contains(const T& item) const
423 for (Vix x=first(); 0 != x; next(x)) {
424 if (operator()(x) == item)
434 // $Source: /egcs/carton/cvsfiles/egcs/gcc/testsuite/g++.old-deja/g++.jason/2371.C,v $
437 // $Date: 1997/08/19 07:35:23 $
439 # 1 "/projects/gnu-cygnus/gnu-cygnus-14/mips/lib/gcc-lib/decstation/cygnus-reno-1/g++-include/iostream.h" 1 3
440 // This is part of the iostream library, providing -*- C++ -*- input/output.
441 // Copyright (C) 1991 Per Bothner.
443 // This library is free software; you can redistribute it and/or
444 // modify it under the terms of the GNU Library General Public
445 // License as published by the Free Software Foundation; either
446 // version 2 of the License, or (at your option) any later version.
448 // This library is distributed in the hope that it will be useful,
449 // but WITHOUT ANY WARRANTY; without even the implied warranty of
450 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
451 // Library General Public License for more details.
453 // You should have received a copy of the GNU Library General Public
454 // License along with this library; if not, write to the Free
455 // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
457 # 211 "/projects/gnu-cygnus/gnu-cygnus-14/mips/lib/gcc-lib/decstation/cygnus-reno-1/g++-include/iostream.h" 3
462 // In (most versions of) g++ 2.X, this use of typedefs has the effect
463 // of causing the instantiation of the templates, thereby testing the
470 test(int v): value(v)
473 void print(ostream& out) const
476 friend int operator==(const test& a, const test& b);
482 operator==(const test& a, const test& b)
484 return a.value == b.value;
488 operator<<(ostream& o, const test& t)
494 typedef SetLS<test> SLS;
497 operator<<(ostream& o, const SLS& s)
499 o << "set of " << s.length() << " = {";
503 for (first=XTRUE, x=s.first(); 0 != x; s.next(x), first=XFALSE) {
519 const unsigned SIZE = 20;
523 // SetLS(const SetLS<T>&)
527 // Fill sls with some interesting values
528 for (unsigned i=0; i<SIZE; i++) {
537 // void operator=(const SetLS<T>&);
542 // bool contains(const T& item) const
544 for (unsigned i=0; i<SIZE; i++) {
547 int contains = sls.contains(t);
554 if (sls.length() != 0)
561 // void next(Vix& x) const
562 // T& operator()(const Vix& x)
563 // const T& operator()(const Vix& x) const
566 for (cx=csls.first(); 0 != cx; sls.next(cx)) {
567 if ( ! sls.contains(csls(cx)) )
571 cout << "gsls:\t" << gsls << '\n';
572 cout << "gcsls:\t" << gcsls << '\n';
573 cout << "sls:\t" << sls << '\n';
574 cout << "csls:\t" << csls << '\n';
577 // Dummy function so it'll run
580 cout << "PASS" << endl;
583 template class ListS<test>;