Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/forall.cfa

    raca0d2f r39d9b32  
    1010// Created On       : Wed May  9 08:48:15 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb 23 20:29:59 2023
    13 // Update Count     : 91
    14 //
    15 
    16 #include <fstream.hfa>
     12// Last Modified On : Sat Jun  5 10:06:08 2021
     13// Update Count     : 36
     14//
    1715
    1816void g1() {
    19         forall( T ) T f( T p ) { sout | 'f'; return p;  };
    20         void f( int p ) { sout | p; };
    21         void g( void ) { sout | 'g'; };
    22         void h( void (*p)(void) ) { p(); };
    23 
    24         int x = 1;
    25         void (*y)(void) = g;
    26         char z = 'a';
    27         float w = 3.5;
     17        forall( T ) T f( T ) {};
     18        void f( int ) {};
     19        void h( void (*p)(void) ) {};
     20
     21        int x;
     22        void (*y)(void);
     23        char z;
     24        float w;
    2825
    2926        f( x );
     
    3128        f( z );
    3229        f( w );
    33         h( y );
    34         f( y );
    3530        h( f( y ) );
    3631}
    3732
    3833void g2() {
    39         forall( T ) void f( T, T ) { sout | "fT"; }
    40         forall( T, U ) void f( T, U ) { sout | "fTU"; }
     34        forall( T ) void f( T, T ) {}
     35        forall( T, U ) void f( T, U ) {}
    4136
    4237        int x;
    4338        float y;
    44         int * z;
    45         float * w;
    46 
    47         f( x, x );
    48         f( y, y );
    49         f( w, w );
     39        int *z;
     40        float *w;
     41
    5042        f( x, y );
    5143        f( z, w );
     
    5850
    5951forall( T )
    60 void swap( T & left, T & right ) {                                              // by reference
    61     T temp = left;
    62     left = right;
    63     right = temp;
    64 }
    65 
    66 forall( T )
    67 [ T, T ] swap( T i, T j ) {                                                             // by value
    68     return [ j, i ];
    69 }
    70 
    71 forall( T ) trait sumable {
     52void swap( T left, T right ) {
     53        T temp = left;
     54        left = right;
     55        right = temp;
     56}
     57
     58trait sumable( T ) {
    7259        void ?{}( T &, zero_t );                                                        // 0 literal constructor
    7360        T ?+?( T, T );                                                                          // assortment of additions
     
    7764}; // sumable
    7865
    79 forall( T | sumable( T ) )                                                              // use trait
     66forall( T | sumable( T ) )                                              // use trait
    8067T sum( size_t size, T a[] ) {
    8168        T total = 0;                                                                            // initialize by 0 constructor
     
    8572} // sum
    8673
    87 forall( T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &, T ); } )
     74forall( T | { T ?+?( T, T ); T ?++( T & ); [T] ?+=?( T &,T ); } )
    8875T twice( T t ) {
    8976        return t + t;
     
    9582}
    9683
    97 void fred() {
    98         int x = 1, y = 2, a[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
     84int fred() {
     85        int x = 1, y = 2, a[10];
    9986        float f;
    10087
    101         sout | x | y;
    10288        swap( x, y );
    103         sout | x | y | nl | swap( x, y );
    104         // [ x, y ] = swap( y, x );
    105         sout | twice( ' ' ) | ' ' | twice( 0hh ) | twice( 1h ) | twice( 0n ) | twice( 2 )
    106                  | twice( 3.2f ) | twice( 3.2 ) | twice( 3.2d ) | twice( 3.2+1.5i ) | twice( x );
     89        twice( x );
    10790        f = min( 4.0, 3.0 );
    108         sout | f | min( 4.0, 3.0 );
    109         sout | sum( 10, a );
     91        sum( 10, a );
    11092}
    11193
     
    195177
    196178forall( T ) struct S { T t; } (int) x, y, z;
    197 static forall( T ) struct { T t; } (int) a, b, c;
     179forall( T ) struct { T t; } (int) a, b, c;
    198180
    199181forall( T ) static forall( S ) {
     
    204186
    205187forall( T ) {
    206 //      extern "C" {
     188        extern "C" {
    207189                struct SS { T t; };
    208                 T foo( T p ) { return p; }
    209 //      }
     190                T foo( T ) {}
     191        }
    210192}
    211193
     
    213195W(int,int) w;
    214196
    215 void jane() {
     197int jane() {
    216198//      int j = bar( 3, 4 );
    217199        int k = baz( 3, 4, 5 );
    218200        int i = foo( 3 );
    219         sout | k | i;
    220201}
    221202
     
    230211        T t;
    231212        T t2 = t;
    232         sout | &tr | tp;
    233213}
    234214
     
    262242
    263243int main( void ) {
    264         g1();
    265         g2();
    266         fred();
    267         jane();
     244    #pragma GCC warning "Compiled"                      // force non-empty .expect file, NO TABS!!!
    268245}
    269246
Note: See TracChangeset for help on using the changeset viewer.