Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/iterator.c

    re56cfdb0 r86bd7c1f  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov 19 17:54:37 2015
    13 // Update Count     : 24
     12// Last Modified On : Wed May 27 18:41:41 2015
     13// Update Count     : 3
    1414//
    1515
    1616#include "iterator.h"
    1717
    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 );
     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 << ' ';
    2235        }
    2336}
    2437
    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; ) {
     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 {
    2845                --i;
    29                 func( *i );
    30         }
     46                os << *i << ' ';
     47        } while ( i != begin );
    3148}
    3249
Note: See TracChangeset for help on using the changeset viewer.