source: src/examples/iterator.c@ 2bae7307

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since 2bae7307 was 843054c2, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

licencing: seventh groups of files

  • Property mode set to 100644
File size: 1.0 KB
Line 
1// "cfa iterator.c"
2// "cfa -CFA iterator.c > iterator_out.c"
3// "gcc31 iterator_out.c ../LibCfa/libcfa.a"
4
5#include "iterator.h"
6
7/// forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
8/// void
9/// for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) )
10/// {
11/// iterator_type i;
12/// for ( i = begin; i != end; ++i ) {
13/// func( *i );
14/// }
15/// }
16
17forall( type elt_type | writeable( elt_type ),
18 type iterator_type | iterator( iterator_type, elt_type ),
19 dtype os_type | ostream( os_type ) )
20void write_all( iterator_type begin, iterator_type end, os_type *os ) {
21 iterator_type i;
22 for ( i = begin; i != end; ++i ) {
23 os << *i << ' ';
24 }
25}
26
27forall( type elt_type | writeable( elt_type ),
28 type iterator_type | iterator( iterator_type, elt_type ),
29 dtype os_type | ostream( os_type ) )
30void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
31 iterator_type i; // "= end;" does not work
32 i = end;
33 do {
34 --i;
35 os << *i << ' ';
36 } while ( i != begin );
37}
Note: See TracBrowser for help on using the repository browser.