Differences From Artifact [fcea1bf69fccc37f]:
- File
polemy/tricks.d
- 2010-11-08 11:57:48 - part of checkin [077506b38c] on branch trunk - Generic toString utility added. (user: kinaba) [annotate]
To Artifact [73906cba073bce6c]:
- File
polemy/tricks.d
- 2010-11-08 12:26:39 - part of checkin [80ff567c75] on branch trunk - Testing easyAST. (user: kinaba) [annotate]
113 113 assert_throw!AssertError( assert_eq(new Temp, 2) );
114 114 }
115 115
116 116 /* [Todo] is there any way to clearnly implement "assert_compiles" and "assert_not_compile"? */
117 117
118 118 /// Mixing-in the bean constructor for a class
119 119
120 -/*mixin*/ template SimpleConstructor()
120 +/*mixin*/
121 +template SimpleConstructor()
121 122 {
122 123 static if( is(typeof(super) == Object) || super.tupleof.length==0 )
123 124 this( typeof(this.tupleof) params )
124 125 {
125 126 static if(this.tupleof.length>0)
126 127 this.tupleof = params;
127 128 }
................................................................................
169 170 mixin SimpleConstructor;
170 171 }
171 172 }) );
172 173 }
173 174
174 175 /// Mixing-in the MOST-DERIVED-member-wise comparator for a class
175 176
176 -/*mixin*/ template SimpleCompare()
177 +/*mixin*/
178 +template SimpleCompare()
177 179 {
178 180 override bool opEquals(Object rhs_) const
179 181 {
180 182 if( auto rhs = cast(typeof(this))rhs_ )
181 183 {
182 184 foreach(i,_; this.tupleof)
183 185 if( this.tupleof[i] != rhs.tupleof[i] )
................................................................................
234 236 }
235 237 assert_throw!AssertError( new Temp(1,"foo") == new TempDummy(1,"foo") );
236 238 assert_throw!AssertError( new Temp(1,"foo") <= new TempDummy(1,"foo") );
237 239 }
238 240
239 241 /// Mixing-in a simple toString method
240 242
241 -/*mixin*/ template SimpleToString()
243 +/*mixin*/
244 +template SimpleToString()
242 245 {
243 246 override string toString()
244 247 {
245 248 string str = sprintf!"%s("(typeof(this).stringof);
246 249 foreach(i,mem; this.tupleof)
247 250 {
248 251 if(i) str ~= ",";
................................................................................
264 267 string y;
265 268 BigInt z;
266 269 mixin SimpleConstructor;
267 270 mixin SimpleToString;
268 271 }
269 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 +}