Check-in [4d8c31f393]
Not logged in
Overview
SHA1 Hash:4d8c31f3932c214f29838471bb4777cf5311255d
Date: 2012-07-14 13:39:21
User: kinaba
Comment:Add standard D-lang util.
Timelines: family | ancestors | descendants | both | trunk
Diffs: redesign
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Added util.d version [8d98b81c5616ea88]

1 +public import std.algorithm; 2 +public import std.array; 3 +public import std.conv; 4 +public import std.range; 5 +public import std.stdio; 6 +public import std.string; 7 +public import std.typecons; 8 + 9 +template DeriveCreate() 10 +{ 11 + this(TS...)(TS params) 12 + { 13 + this.tupleof = params; 14 + } 15 +} 16 + 17 +template DeriveCompare() 18 +{ 19 +override: 20 + bool opEquals(Object rhs) 21 + { 22 + return tuple(this.tupleof) == tuple((cast(typeof(this))rhs).tupleof); 23 + } 24 + 25 + int opCmp(Object rhs) 26 + { 27 + return tuple(this.tupleof).opCmp(tuple((cast(typeof(this))rhs).tupleof)); 28 + } 29 + 30 + hash_t toHash() 31 + { 32 + hash_t v = 0; 33 + foreach(mem; this.tupleof) { 34 + v *= 11; 35 + static if(__traits(compiles, v^=mem)) 36 + v ^= mem; 37 + else 38 + v ^= typeid(mem).getHash(&mem); 39 + } 40 + return v; 41 + } 42 +} 43 + 44 +template DeriveShow() 45 +{ 46 +override: 47 + string toString() 48 + { 49 + string str = text(typeof(this).stringof, "("); 50 + foreach(i,mem; this.tupleof) { 51 + if(i) str ~= ", "; 52 + str = text(str, this.tupleof[i].stringof[5..$], ":", mem); 53 + } 54 + return str ~ ")"; 55 + } 56 +}