Ignore:
Timestamp:
Nov 19, 2015, 6:06:12 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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
Message:

allow nested routines to use type variables in containing scope, fix missing adapters, generalized iostream write

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/iterator.c

    rd2ded3e7 re56cfdb0  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:41:41 2015
    13 // Update Count     : 3
     12// Last Modified On : Thu Nov 19 17:54:37 2015
     13// Update Count     : 24
    1414//
    1515
    1616#include "iterator.h"
    1717
    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 << ' ';
     18forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
     19void for_each( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) {
     20        for ( iterator_type i = begin; i != end; ++i ) {
     21                func( *i );
    3522        }
    3623}
    3724
    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 {
     25forall( type iterator_type, type elt_type | iterator( iterator_type, elt_type ) )
     26void for_each_reverse( iterator_type begin, iterator_type end, void (*func)( elt_type ) ) {
     27        for ( iterator_type i = end; i != begin; ) {
    4528                --i;
    46                 os << *i << ' ';
    47         } while ( i != begin );
     29                func( *i );
     30        }
    4831}
    4932
Note: See TracChangeset for help on using the changeset viewer.