Differences From Artifact [00969146488cc3dc]:
- File
tricks/tricks.d
- 2010-11-24 17:44:58 - part of checkin [b993a8ad16] on branch trunk - auto memo and re-run feature of non @value/@macro layers re-re-re-implemented. (user: kinaba) [annotate]
To Artifact [784e82178988239d]:
- File
tricks/tricks.d
- 2010-11-26 12:22:18 - part of checkin [23fb1b4a0e] on branch trunk - jikken before non-memo macro (user: kinaba) [annotate]
101 } 101 }
102 102
103 hash_t structuralHash(T)(T x) 103 hash_t structuralHash(T)(T x)
104 { 104 {
105 alias SC_Unqual!(T) UCT; 105 alias SC_Unqual!(T) UCT;
106 106
107 static if(is(UCT == class)) 107 static if(is(UCT == class))
108 return (cast(UCT)x).toHash(); | 108 return (x is null ? 0 : (cast(UCT)x).toHash());
109 else 109 else
110 static if(SC_HasGoodHash!(UCT)) 110 static if(SC_HasGoodHash!(UCT))
111 { return typeid(UCT).getHash(&x); } 111 { return typeid(UCT).getHash(&x); }
112 else 112 else
113 static if(is(UCT T == T[])) 113 static if(is(UCT T == T[]))
114 { hash_t h; foreach(e; x) h+=structuralHash(e); return h; } 114 { hash_t h; foreach(e; x) h+=structuralHash(e); return h; }
115 else 115 else
................................................................................................................................................................................
154 override bool opEquals(Object rhs) const /// member-by-member equality 154 override bool opEquals(Object rhs) const /// member-by-member equality
155 { 155 {
156 return opCmp(rhs) == 0; 156 return opCmp(rhs) == 0;
157 } 157 }
158 158
159 override int opCmp(Object rhs_) const /// member-by-member compare 159 override int opCmp(Object rhs_) const /// member-by-member compare
160 { 160 {
161 if( rhs_ is null ) <
162 return -1; <
163 if( auto rhs = cast(typeof(this))rhs_ ) 161 if( auto rhs = cast(typeof(this))rhs_ )
164 { 162 {
165 foreach(i,_; this.tupleof) 163 foreach(i,_; this.tupleof)
166 { 164 {
167 static if(is(typeof(_) == struct)) 165 static if(is(typeof(_) == struct))
168 auto c = (cast(SC_Unqual!(typeof(_)))thi 166 auto c = (cast(SC_Unqual!(typeof(_)))thi
169 else 167 else