Changes in src/examples/iterator.h [86bd7c1f:843054c2]
- File:
-
- 1 edited
-
src/examples/iterator.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/examples/iterator.h
r86bd7c1f r843054c2 1 //2 // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo3 //4 // The contents of this file are covered under the licence agreement in the5 // file "LICENCE" distributed with Cforall.6 //7 // iterator.h --8 //9 // Author : Richard C. Bilson10 // Created On : Wed May 27 17:56:53 201511 // Last Modified By : Peter A. Buhr12 // Last Modified On : Wed May 27 18:41:57 201513 // Update Count : 314 //15 16 1 #ifndef ITERATOR_H 17 2 #define ITERATOR_H … … 21 6 // An iterator can be used to traverse a data structure. 22 7 context iterator( type iterator_type, type elt_type ) { 23 // point to the next element24 // iterator_type ?++( iterator_type * );25 iterator_type ++?( iterator_type * );26 iterator_type --?( iterator_type * );8 // point to the next element 9 // iterator_type ?++( iterator_type * ); 10 iterator_type ++?( iterator_type * ); 11 iterator_type --?( iterator_type * ); 27 12 28 // can be tested for equality with other iterators29 int ?==?( iterator_type, iterator_type );30 int ?!=?( iterator_type, iterator_type );13 // can be tested for equality with other iterators 14 int ?==?( iterator_type, iterator_type ); 15 int ?!=?( iterator_type, iterator_type ); 31 16 32 // dereference to get the pointed-at element33 lvalue elt_type *?( iterator_type );17 // dereference to get the pointed-at element 18 lvalue elt_type *?( iterator_type ); 34 19 }; 35 20 36 21 context iterator_for ( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) { 37 // [ iterator_type begin, iterator_type end ] get_iterators( collection_type );38 iterator_type begin( collection_type );39 iterator_type end( collection_type );22 // [ iterator_type begin, iterator_type end ] get_iterators( collection_type ); 23 iterator_type begin( collection_type ); 24 iterator_type end( collection_type ); 40 25 }; 41 26 … … 45 30 // writes the range [begin, end) to the given stream 46 31 forall( type elt_type | writeable( elt_type ), 47 type iterator_type | iterator( iterator_type, elt_type ),48 dtype os_type | ostream( os_type ) )32 type iterator_type | iterator( iterator_type, elt_type ), 33 dtype os_type | ostream( os_type ) ) 49 34 void write_all( iterator_type begin, iterator_type end, os_type *os ); 50 35 51 36 forall( type elt_type | writeable( elt_type ), 52 type iterator_type | iterator( iterator_type, elt_type ),53 dtype os_type | ostream( os_type ) )37 type iterator_type | iterator( iterator_type, elt_type ), 38 dtype os_type | ostream( os_type ) ) 54 39 void write_reverse( iterator_type begin, iterator_type end, os_type *os ); 55 40 56 41 #endif // ITERATOR_H 57 58 // Local Variables: //59 // tab-width: 4 //60 // compile-command: "cfa iterator.c" //61 // End: //
Note:
See TracChangeset
for help on using the changeset viewer.