[86bd7c1f] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[d3b7937] | 7 | // iterator -- |
---|
[86bd7c1f] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Wed May 27 17:56:53 2015 |
---|
| 11 | // Last Modified By : Peter A. Buhr |
---|
[4040425] | 12 | // Last Modified On : Wed Mar 2 18:06:05 2016 |
---|
| 13 | // Update Count : 9 |
---|
[86bd7c1f] | 14 | // |
---|
| 15 | |
---|
[17e5e2b] | 16 | #ifdef __CFORALL__ |
---|
| 17 | |
---|
[51b73452] | 18 | #ifndef ITERATOR_H |
---|
| 19 | #define ITERATOR_H |
---|
| 20 | |
---|
[134b86a] | 21 | // An iterator can be used to traverse a data structure. |
---|
[4040425] | 22 | trait iterator( otype iterator_type, otype elt_type ) { |
---|
[86bd7c1f] | 23 | // point to the next element |
---|
| 24 | // iterator_type ?++( iterator_type * ); |
---|
| 25 | iterator_type ++?( iterator_type * ); |
---|
| 26 | iterator_type --?( iterator_type * ); |
---|
[134b86a] | 27 | |
---|
[86bd7c1f] | 28 | // can be tested for equality with other iterators |
---|
| 29 | int ?==?( iterator_type, iterator_type ); |
---|
| 30 | int ?!=?( iterator_type, iterator_type ); |
---|
[134b86a] | 31 | |
---|
[86bd7c1f] | 32 | // dereference to get the pointed-at element |
---|
| 33 | lvalue elt_type *?( iterator_type ); |
---|
[51b73452] | 34 | }; |
---|
| 35 | |
---|
[4040425] | 36 | trait iterator_for( otype iterator_type, otype collection_type, otype elt_type | iterator( iterator_type, elt_type ) ) { |
---|
[86bd7c1f] | 37 | // [ iterator_type begin, iterator_type end ] get_iterators( collection_type ); |
---|
| 38 | iterator_type begin( collection_type ); |
---|
| 39 | iterator_type end( collection_type ); |
---|
[51b73452] | 40 | }; |
---|
| 41 | |
---|
[4040425] | 42 | forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) |
---|
[51b73452] | 43 | void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ); |
---|
| 44 | |
---|
[4040425] | 45 | forall( otype iterator_type, otype elt_type | iterator( iterator_type, elt_type ) ) |
---|
[e56cfdb0] | 46 | void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ); |
---|
[134b86a] | 47 | |
---|
| 48 | #endif // ITERATOR_H |
---|
[86bd7c1f] | 49 | |
---|
[17e5e2b] | 50 | #else |
---|
| 51 | #include_next <iterator> |
---|
| 52 | #endif //__CFORALL__ |
---|
| 53 | |
---|
[86bd7c1f] | 54 | // Local Variables: // |
---|
[d3b7937] | 55 | // mode: c // |
---|
[86bd7c1f] | 56 | // tab-width: 4 // |
---|
| 57 | // End: // |
---|