Ignore:
Timestamp:
Nov 19, 2015, 6:06:12 PM (10 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, stuck-waitfor-destruct, 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/iostream.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:18:13 2015
    13 // Update Count     : 2
     12// Last Modified On : Thu Nov 19 17:54:38 2015
     13// Update Count     : 4
    1414//
    1515
     
    3030forall( dtype ostype | ostream( ostype ) )
    3131ostype * ?<<?( ostype *os, int i ) {
    32         char buffer[20];      // larger than the largest integer
     32        char buffer[32];                                                                        // larger than the largest integer
    3333        sprintf( buffer, "%d", i );
    3434        return write( os, buffer, strlen( buffer ) );
     
    3737forall( dtype ostype | ostream( ostype ) )
    3838ostype * ?<<?( ostype *os, double d ) {
    39         char buffer[32];      // larger than the largest double
     39        char buffer[32];                                                                        // larger than the largest double
    4040        sprintf( buffer, "%g", d );
    4141        return write( os, buffer, strlen( buffer ) );
     
    4646        return write( os, cp, strlen( cp ) );
    4747}
     48
     49forall( dtype ostype | ostream( ostype ) )
     50ostype * ?<<?( ostype *os, const void *p ) {
     51        char buffer[32];                                                                        // larger than the largest pointer
     52        sprintf( buffer, "%p", p );
     53        return write( os, buffer, strlen( buffer ) );
     54}
     55
     56forall( type elt_type | writeable( elt_type ),
     57                type iterator_type | iterator( iterator_type, elt_type ),
     58                dtype os_type | ostream( os_type ) )
     59void write( iterator_type begin, iterator_type end, os_type *os ) {
     60        void print( elt_type i ) {
     61                os << i << ' ';
     62        }
     63        for_each( begin, end, print );
     64}
     65
     66forall( type elt_type | writeable( elt_type ),
     67                type iterator_type | iterator( iterator_type, elt_type ),
     68                dtype os_type | ostream( os_type ) )
     69void write_reverse( iterator_type begin, iterator_type end, os_type *os ) {
     70        void print( elt_type i ) {
     71                os << i << ' ';
     72        }
     73        for_each_reverse( begin, end, print );
     74}
     75
    4876
    4977forall( dtype istype | istream( istype ) )
Note: See TracChangeset for help on using the changeset viewer.