source: src/examples/iterator.c @ ecb1534

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since ecb1534 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
RevLine 
[51b7345]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;
[a32b204]12///   for ( i = begin; i != end; ++i ) {
[51b7345]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 ) )
[134b86a]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    }
[51b7345]25}
26
[134b86a]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 ) {
[d11f789]31    iterator_type i; // "= end;" does not work
[134b86a]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.