source: src/examples/iterator.c @ cf0941d

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 cf0941d was 86bd7c1f, checked in by Peter A. Buhr <pabuhr@…>, 9 years ago

licencing: eighth groups of files

  • Property mode set to 100644
File size: 1.4 KB
Line 
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//
7// iterator.c --
8//
9// Author           : Richard C. Bilson
10// Created On       : Wed May 27 17:56:53 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed May 27 18:41:41 2015
13// Update Count     : 3
14//
15
16#include "iterator.h"
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
28forall( type elt_type | writeable( elt_type ),
29                type iterator_type | iterator( iterator_type, elt_type ),
30                dtype os_type | ostream( os_type ) )
31void 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 << ' ';
35        }
36}
37
38forall( type elt_type | writeable( elt_type ),
39                type iterator_type | iterator( iterator_type, elt_type ),
40                dtype os_type | ostream( os_type ) )
41void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
42        iterator_type i; // "= end;" does not work
43        i = end;
44        do {
45                --i;
46                os << *i << ' ';
47        } while ( i != begin );
48}
49
50// Local Variables: //
51// tab-width: 4 //
52// compile-command: "cfa iterator.c" //
53// End: //
Note: See TracBrowser for help on using the repository browser.