source: translator/examples/iterator.h @ d11f789

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

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

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[51b7345]1#ifndef ITERATOR_H
2#define ITERATOR_H
3
4#include "iostream.h"
5
[134b86a]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 );
[51b7345]19};
20
[134b86a]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 );
[51b7345]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
[134b86a]30// writes the range [begin, end) to the given stream
[51b7345]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
[134b86a]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.