Diff
Not logged in

Differences From Artifact [fcea1bf69fccc37f]:

To Artifact [73906cba073bce6c]:


113 assert_throw!AssertError( assert_eq(new Temp, 2) ); 113 assert_throw!AssertError( assert_eq(new Temp, 2) ); 114 } 114 } 115 115 116 /* [Todo] is there any way to clearnly implement "assert_compiles" and "assert_n 116 /* [Todo] is there any way to clearnly implement "assert_compiles" and "assert_n 117 117 118 /// Mixing-in the bean constructor for a class 118 /// Mixing-in the bean constructor for a class 119 119 > 120 /*mixin*/ 120 /*mixin*/ template SimpleConstructor() | 121 template SimpleConstructor() 121 { 122 { 122 static if( is(typeof(super) == Object) || super.tupleof.length==0 ) 123 static if( is(typeof(super) == Object) || super.tupleof.length==0 ) 123 this( typeof(this.tupleof) params ) 124 this( typeof(this.tupleof) params ) 124 { 125 { 125 static if(this.tupleof.length>0) 126 static if(this.tupleof.length>0) 126 this.tupleof = params; 127 this.tupleof = params; 127 } 128 } ................................................................................................................................................................................ 169 mixin SimpleConstructor; 170 mixin SimpleConstructor; 170 } 171 } 171 }) ); 172 }) ); 172 } 173 } 173 174 174 /// Mixing-in the MOST-DERIVED-member-wise comparator for a class 175 /// Mixing-in the MOST-DERIVED-member-wise comparator for a class 175 176 > 177 /*mixin*/ 176 /*mixin*/ template SimpleCompare() | 178 template SimpleCompare() 177 { 179 { 178 override bool opEquals(Object rhs_) const 180 override bool opEquals(Object rhs_) const 179 { 181 { 180 if( auto rhs = cast(typeof(this))rhs_ ) 182 if( auto rhs = cast(typeof(this))rhs_ ) 181 { 183 { 182 foreach(i,_; this.tupleof) 184 foreach(i,_; this.tupleof) 183 if( this.tupleof[i] != rhs.tupleof[i] ) 185 if( this.tupleof[i] != rhs.tupleof[i] ) ................................................................................................................................................................................ 234 } 236 } 235 assert_throw!AssertError( new Temp(1,"foo") == new TempDummy(1,"foo") ); 237 assert_throw!AssertError( new Temp(1,"foo") == new TempDummy(1,"foo") ); 236 assert_throw!AssertError( new Temp(1,"foo") <= new TempDummy(1,"foo") ); 238 assert_throw!AssertError( new Temp(1,"foo") <= new TempDummy(1,"foo") ); 237 } 239 } 238 240 239 /// Mixing-in a simple toString method 241 /// Mixing-in a simple toString method 240 242 > 243 /*mixin*/ 241 /*mixin*/ template SimpleToString() | 244 template SimpleToString() 242 { 245 { 243 override string toString() 246 override string toString() 244 { 247 { 245 string str = sprintf!"%s("(typeof(this).stringof); 248 string str = sprintf!"%s("(typeof(this).stringof); 246 foreach(i,mem; this.tupleof) 249 foreach(i,mem; this.tupleof) 247 { 250 { 248 if(i) str ~= ","; 251 if(i) str ~= ","; ................................................................................................................................................................................ 264 string y; 267 string y; 265 BigInt z; 268 BigInt z; 266 mixin SimpleConstructor; 269 mixin SimpleConstructor; 267 mixin SimpleToString; 270 mixin SimpleToString; 268 } 271 } 269 assert_eq( (new Temp(1,"foo",BigInt(42))).toString(), "Temp(1,foo,42)" ) 272 assert_eq( (new Temp(1,"foo",BigInt(42))).toString(), "Temp(1,foo,42)" ) 270 } 273 } > 274 > 275 /// Everything is in > 276 > 277 /*mixin*/ > 278 template SimpleClass() > 279 { > 280 mixin SimpleConstructor; > 281 mixin SimpleCompare; > 282 mixin SimpleToString; > 283 }