Changeset 134b86a for translator/examples/iterator.h
- Timestamp:
- Nov 3, 2014, 4:38:08 PM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
- Children:
- 8c17ab0
- Parents:
- 93885663
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
translator/examples/iterator.h
r93885663 r134b86a 4 4 #include "iostream.h" 5 5 6 context iterator( type iterator_type, type elt_type ) 7 { 8 iterator_type ?++( iterator_type* ); 9 iterator_type ++?( iterator_type* ); 10 int ?==?( iterator_type, iterator_type ); 11 int ?!=?( iterator_type, iterator_type ); 12 lvalue elt_type *?( iterator_type ); 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 ); 13 19 }; 14 20 15 context iterator_for( type iterator_type, type collection_type, type elt_type | iterator( iterator_type, elt_type ) ) 16 { 17 /// [ iterator_type begin, iterator_type end ] get_iterators( collection_type ); 18 iterator_type get_begin( collection_type ); 19 iterator_type get_end( collection_type ); 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 ); 20 25 }; 21 26 … … 23 28 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ); 24 29 30 // writes the range [begin, end) to the given stream 25 31 forall( type elt_type | writeable( elt_type ), 26 32 type iterator_type | iterator( iterator_type, elt_type ), … … 28 34 void write_all( iterator_type begin, iterator_type end, os_type *os ); 29 35 30 #endif /* #ifndef ITERATOR_H */ 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
Note: See TracChangeset
for help on using the changeset viewer.