1 | #ifndef ITERATOR_H
|
---|
2 | #define ITERATOR_H
|
---|
3 |
|
---|
4 | #include "iostream.h"
|
---|
5 |
|
---|
6 | // An iterator can be used to traverse a data structure.
|
---|
7 | context iterator( type iterator_type, type elt_type ) {
|
---|
8 | // point to the next element
|
---|
9 | // iterator_type ?++( iterator_type * );
|
---|
10 | iterator_type ++?( iterator_type * );
|
---|
11 | iterator_type --?( iterator_type * );
|
---|
12 |
|
---|
13 | // can be tested for equality with other iterators
|
---|
14 | int ?==?( iterator_type, iterator_type );
|
---|
15 | int ?!=?( iterator_type, iterator_type );
|
---|
16 |
|
---|
17 | // dereference to get the pointed-at element
|
---|
18 | lvalue elt_type *?( iterator_type );
|
---|
19 | };
|
---|
20 |
|
---|
21 | context iterator_for ( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) {
|
---|
22 | // [ iterator_type begin, iterator_type end ] get_iterators( collection_type );
|
---|
23 | iterator_type begin( collection_type );
|
---|
24 | iterator_type end( collection_type );
|
---|
25 | };
|
---|
26 |
|
---|
27 | forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
|
---|
28 | void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
|
---|
29 |
|
---|
30 | // writes the range [begin, end) to the given stream
|
---|
31 | forall( type elt_type | writeable( elt_type ),
|
---|
32 | type iterator_type | iterator( iterator_type, elt_type ),
|
---|
33 | dtype os_type | ostream( os_type ) )
|
---|
34 | void write_all( iterator_type begin, iterator_type end, os_type *os );
|
---|
35 |
|
---|
36 | forall( type elt_type | writeable( elt_type ),
|
---|
37 | type iterator_type | iterator( iterator_type, elt_type ),
|
---|
38 | dtype os_type | ostream( os_type ) )
|
---|
39 | void write_reverse( iterator_type begin, iterator_type end, os_type *os );
|
---|
40 |
|
---|
41 | #endif // ITERATOR_H
|
---|