#include #include forall( [N] ) void print1d_cstyle( array( float, N ) & r ); $\C{// C style}$ forall( [N], C & @| ar( C, float, N )@ ) $\C{// add trait}$ void print1d( C & c ); forall( [N] ) void print1d_cstyle( array( float, N ) & r ) { $\C{// C style}$ for ( i; N ) sout | r[i] | nonl; sout | nl; } forall( [N], C & | ar( C, float, N ) ) void print1d( C & c ) { for( i; N ) { sout | c[i] | nonl; } sout | nl; } void fill( array( float, 5, 7 ) & a ) { for ( i; (ptrdiff_t) 5 ) { for ( j; 7 ) { a[i,j] = 1.0 * i + 0.1 * j; sout | a[[i,j]] | nonl; } sout | nl; } sout | nl; } int main() { array( float, 5, 7 ) m; fill( m ); /* r/c 0 1 2 3 4 5 6 0 0.0 0.1 0.2 @0.3@ 0.4 0.5 0.6 1 1.0 1.1 1.2 @1.3@ 1.4 1.5 1.6 2 @2.0 2.1 2.2 2.3 2.4 2.5 2.6@ 3 3.0 3.1 3.2 @3.3@ 3.4 3.5 3.6 4 4.0 4.1 4.2 @4.3@ 4.4 4.5 4.6 */ print1d_cstyle( m[ 2 ] ); $\C{// row 2: 2.0 2.1 2.2 2.3 2.4 2.5 2.6}$ print1d( m[ 2 ] ); $\C{// row: 2.0 2.1 2.2 2.3 2.4 2.5 2.6}$ print1d( m[ 2, all ] ); $\C{// row 2: 2.0 2.1 2.2 2.3 2.4 2.5 2.6}$ print1d( m[ all, 3 ] ); $\C{// column 3: 0.3 1.3 2.3 3.3 4.3}$ print1d_cstyle( m[ 2, all ] ); #ifdef SHOW_ERROR_1 print1d_cstyle( m[ all, 2 ] ); $\C{// bad}$ #endif }