- File:
-
- 1 edited
-
libcfa/src/containers/array.hfa (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/containers/array.hfa
ra5e26821 r058ece2 1 #pragma once2 3 1 #include <assert.h> 4 2 … … 20 18 // About the choice of integral types offered as subscript overloads: 21 19 // Intent is to cover these use cases: 22 // a[0] // i : zero_t23 // a[1] // i : one_t24 // a[2] // i : int25 20 // float foo( ptrdiff_t i ) { return a[i]; } // i : ptrdiff_t 26 // float foo( size_t i ) { return a[i]; } // i : size_t27 21 // forall( [N] ) ... for( i; N ) { total += a[i]; } // i : typeof( sizeof(42) ) 28 22 // for( i; 5 ) { total += a[i]; } // i : int 29 //30 23 // It gets complicated by: 31 24 // - CFA does overloading on concrete types, like int and unsigned int, not on typedefed … … 35 28 // should give them type size_t. 36 29 // 37 // gcc -m32 cfa -m32 given bug gcc -m64 (and cfa)30 // gcc -m32 cfa -m32 given bug gcc -m64 38 31 // ptrdiff_t int int long int 39 32 // size_t unsigned int unsigned int unsigned long int 40 33 // typeof( sizeof(42) ) unsigned int unsigned long int unsigned long int 41 34 // int int int int 42 //43 // So the solution must support types {zero_t, one_t, int, unsigned int, long int, unsigned long int}44 //45 // The solution cannot rely on implicit conversions (e.g. just have one overload for ptrdiff_t)46 // because assertion satisfaction requires types to match exacly. Both higher-dimensional47 // subscripting and operations on slices use asserted subscript operators. The test case48 // array-container/array-sbscr-cases covers the combinations. Mike beleives that commenting out49 // any of the current overloads leads to one of those cases failing, either on 64- or 32-bit.50 // Mike is open to being shown a smaller set of overloads that still passes the test.51 52 static inline Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, zero_t ) {53 assert( 0 < N );54 return (Timmed &) a.strides[0];55 }56 57 static inline Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, one_t ) {58 assert( 1 < N );59 return (Timmed &) a.strides[1];60 }61 35 62 36 static inline Timmed & ?[?]( arpk(N, S, Timmed, Tbase) & a, int i ) { … … 103 77 return N; 104 78 } 105 106 static inline void __taglen( tag(arpk(N, S, Timmed, Tbase)), tag(N) ) {}107 79 108 80 // workaround #226 (and array relevance thereof demonstrated in mike102/otype-slow-ndims.cfa) … … 184 156 #endif 185 157 186 // Available for users to work around Trac #265187 // If `a[...0...]` isn't working, try `a[...ix0...]` instead.188 189 #define ix0 ((ptrdiff_t)0)190 191 192 193 158 // 194 159 // Rotation … … 220 185 // 221 186 222 // desired: 223 // trait ar(A &, Tv &, [N]) { 224 // Tv& ?[?]( A&, zero_t ); 225 // Tv& ?[?]( A&, one_t ); 226 // Tv& ?[?]( A&, int ); 227 // ... 228 // size_t ?`len( A& ); 229 // void __taglen( tag(C), tag(N) ); 230 // }; 231 232 // working around N's not being accepted as arguments to traits 233 234 #define ar(A, Tv, N) { \ 235 Tv& ?[?]( A&, zero_t ); \ 236 Tv& ?[?]( A&, one_t ); \ 237 Tv& ?[?]( A&, int ); \ 238 Tv& ?[?]( A&, unsigned int ); \ 239 Tv& ?[?]( A&, long int ); \ 240 Tv& ?[?]( A&, unsigned long int ); \ 241 size_t ?`len( A& ); \ 242 void __taglen( tag(A), tag(N) ); \ 243 } 187 trait ar(A &, Tv &) { 188 Tv& ?[?]( A&, ptrdiff_t ); 189 size_t ?`len( A& ); 190 };
Note:
See TracChangeset
for help on using the changeset viewer.