Changeset e56cfdb0 for src/examples/iterator.c
- Timestamp:
- Nov 19, 2015, 6:06:12 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:
- 05587c2
- Parents:
- d2ded3e7
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/examples/iterator.c
rd2ded3e7 re56cfdb0 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed May 27 18:41:41201513 // Update Count : 312 // Last Modified On : Thu Nov 19 17:54:37 2015 13 // Update Count : 24 14 14 // 15 15 16 16 #include "iterator.h" 17 17 18 /// forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) ) 19 /// void 20 /// for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) 21 /// { 22 /// iterator_type i; 23 /// for ( i = begin; i != end; ++i ) { 24 /// func( *i ); 25 /// } 26 /// } 27 28 forall( type elt_type | writeable( elt_type ), 29 type iterator_type | iterator( iterator_type, elt_type ), 30 dtype os_type | ostream( os_type ) ) 31 void write_all( iterator_type begin, iterator_type end, os_type *os ) { 32 iterator_type i; 33 for ( i = begin; i != end; ++i ) { 34 os << *i << ' '; 18 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) ) 19 void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) { 20 for ( iterator_type i = begin; i != end; ++i ) { 21 func( *i ); 35 22 } 36 23 } 37 24 38 forall( type elt_type | writeable( elt_type ), 39 type iterator_type | iterator( iterator_type, elt_type ), 40 dtype os_type | ostream( os_type ) ) 41 void write_reverse( iterator_type begin, iterator_type end, os_type *os ) { 42 iterator_type i; // "= end;" does not work 43 i = end; 44 do { 25 forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) ) 26 void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) { 27 for ( iterator_type i = end; i != begin; ) { 45 28 --i; 46 os << *i << ' ';47 } while ( i != begin );29 func( *i ); 30 } 48 31 } 49 32
Note: See TracChangeset
for help on using the changeset viewer.