source: translator/examples/iterator.h @ 134b86a

aaron-thesisarm-ehcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationresolv-newstringwith_gc
Last change on this file since 134b86a was 134b86a, checked in by Peter A. Buhr <pabuhr@…>, 8 years ago

add compiler flag to driver, update examples, fix unnamed bit fields

  • Property mode set to 100644
File size: 1.5 KB
Line 
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.
7context 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
21context 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
27forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
28void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) );
29
30// writes the range [begin, end) to the given stream
31forall( type elt_type | writeable( elt_type ),
32        type iterator_type | iterator( iterator_type, elt_type ),
33        dtype os_type | ostream( os_type ) )
34void write_all( iterator_type begin, iterator_type end, os_type *os );
35
36forall( type elt_type | writeable( elt_type ),
37        type iterator_type | iterator( iterator_type, elt_type ),
38        dtype os_type | ostream( os_type ) )
39void write_reverse( iterator_type begin, iterator_type end, os_type *os );
40
41#endif // ITERATOR_H
Note: See TracBrowser for help on using the repository browser.