// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // forall.cfa -- // // Author : Peter A. Buhr // Created On : Wed May 9 08:48:15 2018 // Last Modified By : Peter A. Buhr // Last Modified On : Thu Feb 23 20:29:59 2023 // Update Count : 91 // #include void g1() { forall( T ) T f( T p ) { sout | 'f'; return p; }; void f( int p ) { sout | p; }; void g( void ) { sout | 'g'; }; void h( void (*p)(void) ) { p(); }; int x = 1; void (*y)(void) = g; char z = 'a'; float w = 3.5; f( x ); f( y ); f( z ); f( w ); h( y ); f( y ); h( f( y ) ); } void g2() { forall( T ) void f( T, T ) { sout | "fT"; } forall( T, U ) void f( T, U ) { sout | "fTU"; } int x; float y; int * z; float * w; f( x, x ); f( y, y ); f( w, w ); f( x, y ); f( z, w ); f( x, z ); } // commented this out since it is not clearly meaningful // and not really representable in the ast // typedef forall ( T ) int (* f)( int ); forall( T ) void swap( T & left, T & right ) { // by reference T temp = left; left = right; right = temp; } forall( T ) [ T, T ] swap( T i, T j ) { // by value return [ j, i ]; } forall( T ) trait sumable { void ?{}( T &, zero_t ); // 0 literal constructor T ?+?( T, T ); // assortment of additions T ?+=?( T &, T ); T ++?( T & ); T ?++( T & ); }; // sumable forall( T | sumable( T ) ) // use trait T sum( size_t size, T a[] ) { T total = 0; // initialize by 0 constructor for ( size_t i = 0; i < size; i += 1 ) total = total + a[i]; // select appropriate + return total; } // sum forall( T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &, T ); } ) T twice( T t ) { return t + t; } forall( T | { int ?