4d8c31f393 2012-07-14 kinaba: public import std.algorithm; 4d8c31f393 2012-07-14 kinaba: public import std.array; 4d8c31f393 2012-07-14 kinaba: public import std.conv; 4d8c31f393 2012-07-14 kinaba: public import std.range; 4d8c31f393 2012-07-14 kinaba: public import std.stdio; 4d8c31f393 2012-07-14 kinaba: public import std.string; 4d8c31f393 2012-07-14 kinaba: public import std.typecons; 4d8c31f393 2012-07-14 kinaba: 4d8c31f393 2012-07-14 kinaba: template DeriveCreate() 4d8c31f393 2012-07-14 kinaba: { 4d8c31f393 2012-07-14 kinaba: this(TS...)(TS params) 4d8c31f393 2012-07-14 kinaba: { 4d8c31f393 2012-07-14 kinaba: this.tupleof = params; 4d8c31f393 2012-07-14 kinaba: } 4d8c31f393 2012-07-14 kinaba: } 4d8c31f393 2012-07-14 kinaba: 4d8c31f393 2012-07-14 kinaba: template DeriveCompare() 4d8c31f393 2012-07-14 kinaba: { 4d8c31f393 2012-07-14 kinaba: override: 4d8c31f393 2012-07-14 kinaba: bool opEquals(Object rhs) 4d8c31f393 2012-07-14 kinaba: { 4d8c31f393 2012-07-14 kinaba: return tuple(this.tupleof) == tuple((cast(typeof(this))rhs).tupleof); 4d8c31f393 2012-07-14 kinaba: } 4d8c31f393 2012-07-14 kinaba: 4d8c31f393 2012-07-14 kinaba: int opCmp(Object rhs) 4d8c31f393 2012-07-14 kinaba: { 4d8c31f393 2012-07-14 kinaba: return tuple(this.tupleof).opCmp(tuple((cast(typeof(this))rhs).tupleof)); 4d8c31f393 2012-07-14 kinaba: } 4d8c31f393 2012-07-14 kinaba: 4d8c31f393 2012-07-14 kinaba: hash_t toHash() 4d8c31f393 2012-07-14 kinaba: { 4d8c31f393 2012-07-14 kinaba: hash_t v = 0; 4d8c31f393 2012-07-14 kinaba: foreach(mem; this.tupleof) { 4d8c31f393 2012-07-14 kinaba: v *= 11; 4d8c31f393 2012-07-14 kinaba: static if(__traits(compiles, v^=mem)) 4d8c31f393 2012-07-14 kinaba: v ^= mem; 4d8c31f393 2012-07-14 kinaba: else 4d8c31f393 2012-07-14 kinaba: v ^= typeid(mem).getHash(&mem); 4d8c31f393 2012-07-14 kinaba: } 4d8c31f393 2012-07-14 kinaba: return v; 4d8c31f393 2012-07-14 kinaba: } 4d8c31f393 2012-07-14 kinaba: } 4d8c31f393 2012-07-14 kinaba: 4d8c31f393 2012-07-14 kinaba: template DeriveShow() 4d8c31f393 2012-07-14 kinaba: { 4d8c31f393 2012-07-14 kinaba: override: 4d8c31f393 2012-07-14 kinaba: string toString() 4d8c31f393 2012-07-14 kinaba: { 4d8c31f393 2012-07-14 kinaba: string str = text(typeof(this).stringof, "("); 4d8c31f393 2012-07-14 kinaba: foreach(i,mem; this.tupleof) { 4d8c31f393 2012-07-14 kinaba: if(i) str ~= ", "; 4d8c31f393 2012-07-14 kinaba: str = text(str, this.tupleof[i].stringof[5..$], ":", mem); 4d8c31f393 2012-07-14 kinaba: } 4d8c31f393 2012-07-14 kinaba: return str ~ ")"; 4d8c31f393 2012-07-14 kinaba: } 4d8c31f393 2012-07-14 kinaba: }