Changes in / [05f8761:5b95e67]
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/collections/array.hfa
r05f8761 r5b95e67 156 156 // other two. This solution offers ?{}() that needs only ?{}(), and similar for ^?{}. 157 157 158 // skip initializing elements 159 // array(float, 5) x = { delay_init }; 160 struct delay_init_t {} delay_init; 161 forall( [N], S & | sized(S), Timmed &, Tbase & ) 162 static inline void ?{}( arpk( N, S, Timmed, Tbase ) & this, delay_init_t ) { 158 forall( [N], S & | sized(S), Timmed &, Tbase & | { void ?{}( Timmed & ); } ) 159 static inline void ?{}( arpk( N, S, Timmed, Tbase ) & this ) { 163 160 void ?{}( S (&)[N] ) {} 164 161 ?{}(this.strides); 165 } 166 167 // call default ctor on elements 168 // array(float, 5) x; 169 forall( [N], S & | sized(S), Timmed &, Tbase & | { void ?{}( Timmed & ); } ) 170 static inline void ?{}( arpk( N, S, Timmed, Tbase ) & this ) { 171 ?{}( this, delay_init ); 162 172 163 for (i; N) ?{}( (Timmed &)this.strides[i] ); 173 164 } … … 182 173 } 183 174 } 184 185 175 186 176 // -
tests/array-collections/.expect/array-raii-c.txt
r05f8761 r5b95e67 70 70 dtor 1 71 71 dtor 0 72 === uninit ( uNoCtor[] )72 === uninit 73 73 [1] 74 74 before ctors -
tests/array-collections/.expect/array-raii-cfa.txt
r05f8761 r5b95e67 70 70 dtor 1 71 71 dtor 0 72 === uninit ( uNoCtor[] )72 === uninit 73 73 [1] 74 74 before ctors … … 108 108 dtor 101 109 109 dtor 100 110 === uninit alt ( uArray )111 [1]112 before ctors113 ctor 0114 ctor 999115 ctor 888116 ctor 3117 ctor 4118 func 0119 func 999120 func 888121 func 3122 func 4123 dtor 4124 dtor 3125 dtor 888126 dtor 999127 dtor 0128 [2]129 before ctors130 ctor 100131 ctor 101132 ctor 102133 ctor 110134 ctor 999135 ctor 888136 func 100 at (0, 0)137 func 101 at (0, 1)138 func 102 at (0, 2)139 func 110 at (1, 0)140 func 999 at (1, 1)141 func 888 at (1, 2)142 dtor 888143 dtor 999144 dtor 110145 dtor 102146 dtor 101147 dtor 100148 === uC++ cheat sheet149 ctor 0150 ctor 1151 ctor 2152 ctor 3153 ctor 4154 0155 1156 2157 3158 4159 dtor 4160 dtor 3161 dtor 2162 dtor 1163 dtor 0 -
tests/array-collections/array-raii-c.cfa
r05f8761 r5b95e67 20 20 21 21 #include "array-raii.hfa" 22 23 void test_extras() {} -
tests/array-collections/array-raii-cfa.cfa
r05f8761 r5b95e67 16 16 // CFA array means like `array(float, 17) x;` 17 17 18 19 #include <fstream.hfa>20 18 #include <collections/array.hfa> 21 19 … … 24 22 25 23 #include "array-raii.hfa" 26 27 void test_uninit_alt() {28 printf(" [1]\n");29 {30 array(thing, 5) a = { delay_init };31 printf("before ctors\n");32 for(i; 5) {33 if (i == 1)34 (a[i]){}; // no need for `emplace` bc no-arg ctor call means elem's real ctor35 else if (i == 2)36 (a[i]){888};37 else38 (a[i]){i};39 }40 for(i; 5) printf("func %d\n", a[i].mem);41 }42 printf(" [2]\n");43 {44 array(thing, 2, 3) a = { delay_init };45 printf("before ctors\n");46 for(i; 2) for(j; 3) {47 if (i == 1 && j == 1)48 (a[i][j]){};49 else if (i == 1 && j == 2)50 (a[i][j]){888};51 else52 (a[i][j]){100 + 10 * i + j};53 }54 for(i; 2) for(j; 3) {55 printf("func %d at (%d, %d)\n", a[i][j].mem, i, j);56 }57 }58 }59 60 void test_uCxxCheatSheet() {61 struct S {62 int i;63 };64 void ?{}( S & s, int i ) { s.i = i; sout | "ctor" | s.i; }65 void ^?{}( S & s ) { sout | "dtor" | s.i; }66 // int main() {67 enum { N = 5 };68 array(S, N) s = { delay_init }; // no constructor calls69 for ( i; N ) s[i]{ i };70 for ( i; N ) sout | s[i].i;71 // }72 }73 74 void test_extras() {75 76 printf("=== uninit alt ( uArray )\n");77 test_uninit_alt();78 79 printf("=== uC++ cheat sheet\n");80 test_uCxxCheatSheet();81 } -
tests/array-collections/array-raii.hfa
r05f8761 r5b95e67 118 118 } 119 119 120 struct thing { int mem; };121 void ?{}( thing & this, int i ) {122 (this.mem){ i };123 printf("ctor %d\n", this.mem);124 }125 void ?{}( thing & this ) {126 (this){ 999 };127 }128 void ^?{}( thing & this ) {129 printf("dtor %d\n", this.mem);130 }131 132 120 // Array of uninits sees explicit ctor calls (only), and implied dtor calls 133 121 void test_uninit() { 122 struct thing { int mem; }; 123 void ?{}( thing & this, int i ) { 124 (this.mem){ i }; 125 printf("ctor %d\n", this.mem); 126 } 127 void ?{}( thing & this ) { 128 (this){ 999 }; 129 } 130 void ^?{}( thing & this ) { 131 printf("dtor %d\n", this.mem); 132 } 134 133 printf(" [1]\n"); 135 134 { … … 164 163 } 165 164 166 void test_extras();167 168 165 int main() { 169 166 printf("=== builtins\n"); … … 173 170 test_custom(); 174 171 175 printf("=== uninit ( uNoCtor[] )\n");172 printf("=== uninit\n"); 176 173 test_uninit(); 177 178 test_extras();179 174 }
Note: See TracChangeset
for help on using the changeset viewer.