lindquist@72: module typeinfo10; lindquist@72: lindquist@72: struct S lindquist@72: { lindquist@72: long l; lindquist@72: float f; lindquist@72: void* vp; lindquist@72: lindquist@72: hash_t toHash() lindquist@72: { lindquist@72: return l + cast(size_t)f; lindquist@72: } lindquist@72: lindquist@72: int opEquals(S s) lindquist@72: { lindquist@72: return (s.l == l) && (s.f == f); lindquist@72: } lindquist@72: lindquist@72: int opCmp(S a) lindquist@72: { lindquist@72: if (l == a.l) { lindquist@72: return (f < a.f) ? -1 : (f > a.f) ? 1 : 0; lindquist@72: } lindquist@72: return (l < a.l) ? -1 : 1; lindquist@72: } lindquist@72: lindquist@72: char[] toString() lindquist@72: { lindquist@72: return "S instance"; lindquist@72: } lindquist@72: } lindquist@72: lindquist@72: void main() lindquist@72: { lindquist@72: S s=S(-1, 0); lindquist@72: S t=S(-1, 1); lindquist@72: S u=S(11,-1); lindquist@72: S v=S(12,13); lindquist@72: lindquist@72: { lindquist@72: assert(s == s); lindquist@72: assert(s != t); lindquist@72: assert(s != v); lindquist@72: assert(s < t); lindquist@72: assert(u > s); lindquist@72: assert(v > u); lindquist@72: } lindquist@72: lindquist@72: { lindquist@72: auto ti = typeid(S); lindquist@72: assert(ti.getHash(&s) == s.toHash()); lindquist@72: assert(ti.equals(&s,&s)); lindquist@72: assert(!ti.equals(&s,&t)); lindquist@72: assert(!ti.equals(&s,&v)); lindquist@72: assert(ti.compare(&s,&s) == 0); lindquist@72: assert(ti.compare(&s,&t) < 0); lindquist@72: assert(ti.compare(&u,&s) > 0); lindquist@72: assert(ti.compare(&v,&u) > 0); lindquist@72: { lindquist@72: auto tis = cast(TypeInfo_Struct)ti; lindquist@72: assert(tis.xtoString(&s) == s.toString()); lindquist@72: } lindquist@72: } lindquist@72: }