1 | #include <fstream.hfa> |
---|
2 | #include <stdlib.hfa> // new, delete |
---|
3 | #include <bits/queue.hfa> |
---|
4 | |
---|
5 | int main() { |
---|
6 | // Fred test |
---|
7 | |
---|
8 | struct Fred { |
---|
9 | inline Colable; // Plan 9 inheritance |
---|
10 | int i; |
---|
11 | }; |
---|
12 | void ?{}( Fred & fred ) { abort(); } |
---|
13 | void ?{}( Fred & fred, int p ) with( fred ) { |
---|
14 | i = p; |
---|
15 | } |
---|
16 | |
---|
17 | Queue(Fred) fred; |
---|
18 | QueueIter(Fred) fredIter = { fred }; |
---|
19 | Fred & f; |
---|
20 | |
---|
21 | sout | nlOff; // turn off auto newline |
---|
22 | |
---|
23 | for ( ; fredIter >> f; ) { // empty list |
---|
24 | sout | f.i | ' '; |
---|
25 | } |
---|
26 | sout | "empty" | nl; |
---|
27 | |
---|
28 | for ( i; 10 ) { |
---|
29 | add( fred, *new( 2 * i ) ); |
---|
30 | } |
---|
31 | |
---|
32 | for ( QueueIter(Fred) iter = { fred }; iter >> f; ) { |
---|
33 | sout | f.i | ' '; |
---|
34 | } |
---|
35 | sout | nl; |
---|
36 | |
---|
37 | for ( i; 9 ) { |
---|
38 | delete( &drop( fred ) ); |
---|
39 | } |
---|
40 | |
---|
41 | for ( over( fredIter, fred ); fredIter >> f; ) { |
---|
42 | sout | f.i | ' '; |
---|
43 | } |
---|
44 | sout | nl; |
---|
45 | |
---|
46 | for ( i; 10 ) { |
---|
47 | add( fred, *new( 2 * i + 1 ) ); |
---|
48 | } |
---|
49 | for ( over( fredIter, fred ); fredIter >> f; ) { |
---|
50 | sout | f.i | ' '; |
---|
51 | } |
---|
52 | sout | nl; |
---|
53 | |
---|
54 | for ( over( fredIter, fred ); fredIter >> f; ) { |
---|
55 | delete( &f ); |
---|
56 | } |
---|
57 | |
---|
58 | // Mary test |
---|
59 | |
---|
60 | struct Mary { |
---|
61 | inline Fred; // Plan 9 inheritance |
---|
62 | int j; |
---|
63 | }; |
---|
64 | void ?{}( Mary & mary ) { abort(); } |
---|
65 | void ?{}( Mary & mary, int p ) with( mary ) { |
---|
66 | ((Fred &)mary){ p }; |
---|
67 | j = i = p; |
---|
68 | } |
---|
69 | |
---|
70 | Queue(Mary) mary; |
---|
71 | QueueIter(Mary) maryIter = { mary }; |
---|
72 | Mary & m; |
---|
73 | |
---|
74 | for ( ; maryIter >> m; ) { // empty list |
---|
75 | sout | m.i | m.j | ' '; |
---|
76 | } |
---|
77 | sout | "empty" | nl; |
---|
78 | |
---|
79 | for ( i; 10 ) { |
---|
80 | add( mary, *new( 2 * i ) ); |
---|
81 | } |
---|
82 | |
---|
83 | for ( QueueIter(Mary) iter = { mary }; iter >> m; ) { |
---|
84 | sout | m.i | m.j | ' '; |
---|
85 | } |
---|
86 | sout | nl; |
---|
87 | |
---|
88 | for ( i; 9 ) { |
---|
89 | delete( &drop( mary ) ); |
---|
90 | } |
---|
91 | |
---|
92 | for ( over( maryIter, mary ); maryIter >> m; ) { |
---|
93 | sout | m.i | m.j | ' '; |
---|
94 | } |
---|
95 | sout | nl; |
---|
96 | |
---|
97 | for ( i; 10 ) { |
---|
98 | add( mary, *new( 2 * i + 1 ) ); |
---|
99 | } |
---|
100 | for ( over( maryIter, mary ); maryIter >> m; ) { |
---|
101 | sout | m.i | m.j | ' '; |
---|
102 | } |
---|
103 | sout | nl; |
---|
104 | |
---|
105 | for ( over( maryIter, mary ); maryIter >> m; ) { |
---|
106 | delete( &m ); |
---|
107 | } |
---|
108 | } |
---|