1 | enum Alphabet { |
---|
2 | A = 'A', B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z, |
---|
3 | a = 'a', b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z |
---|
4 | }; |
---|
5 | |
---|
6 | |
---|
7 | forall( istype & | istream( istype ) | { istype & ?|?( istype &, E & ); } ) |
---|
8 | istype & ?|?( istype & is, E & e ) { |
---|
9 | choose ( e ) { |
---|
10 | case A: is | label( A ); e = A; |
---|
11 | case B: is | label( B ); e = B; |
---|
12 | case C: is | label( C ); e = C; |
---|
13 | } // choose |
---|
14 | return is; |
---|
15 | } |
---|
16 | |
---|
17 | forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, E ); } ) |
---|
18 | ostype & ?|?( ostype & os, E e ) { |
---|
19 | choose ( e ) { |
---|
20 | case A: os | label( A ); |
---|
21 | case B: os | label( B ); |
---|
22 | case C: os | label( C ); |
---|
23 | } // choose |
---|
24 | return os; |
---|
25 | } |
---|
26 | |
---|
27 | enum( char * ) Friends { Fred = "FRED", Mary = "MARY", Jane = "Jane" }; |
---|
28 | |
---|
29 | forall( istype & | istream( istype ) | { istype & ?|?( istype &, Friends & ); } ) |
---|
30 | istype & ?|?( istype & is, Friends & friend ) { |
---|
31 | choose ( friend ) { |
---|
32 | case Fred: is | label( A ); friend = A; |
---|
33 | case Mary: is | label( B ); friend = B; |
---|
34 | case Jane: is | label( C ); friend = C; |
---|
35 | } // choose |
---|
36 | return is; |
---|
37 | } |
---|
38 | |
---|
39 | forall( ostype & | ostream( ostype ) | { ostype & ?|?( ostype &, Friends ); } ) |
---|
40 | ostype & ?|?( ostype & os, Friends friend ) { |
---|
41 | choose ( friend ) { |
---|
42 | case Fred: os | value( Fred ); |
---|
43 | case Mary: os | value( Mary ); |
---|
44 | case Jane: os | value( Jane ); |
---|
45 | } // choose |
---|
46 | return os; |
---|
47 | } |
---|
48 | |
---|
49 | |
---|
50 | int main() { |
---|
51 | E e = A; |
---|
52 | sin | e; |
---|
53 | sout | e; |
---|
54 | Friends friend = Mary; |
---|
55 | sin | friend; |
---|
56 | sout | friend; |
---|
57 | } |
---|