Artifact b76be1f6ad977d56752dcf1616d70912ccc92dbe
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 public import std.math;
9 import std.c.stdlib;
10
11 T[] erase(T,V)(T[] xs, V y)
12 {
13 foreach(i,x; xs)
14 if(x == y)
15 return xs[0..i]~xs[i+1..$];
16 return xs;
17 }
18
19 // To avoide the following ICE:
20 // src\phobos\std\algorithm.d(4552):
21 // Error: function std.algorithm.count!("a == b",string,char).count
22 // compiler error, parameter 'value', bugzilla 2962?
23 // Assertion failure: '0' on line 717 in file 'glue.c'
24 int count(T,V)(T[] a, V v)
25 {
26 int cnt = 0;
27 foreach(e; a)
28 if(e == v)
29 ++cnt;
30 return cnt;
31 }
32
33 void application_exit()
34 {
35 std.c.stdlib.exit(0);
36 }
37
38 template DeriveCreate()
39 {
40 this(TS...)(TS params)
41 {
42 this.tupleof = params;
43 }
44 }
45
46 template DeriveCompare()
47 {
48 override:
49 bool opEquals(Object rhs) const
50 {
51 return tuple(this.tupleof) == tuple((cast(typeof(this))rhs).tupleof);
52 }
53
54 int opCmp(Object rhs) const
55 {
56 return tuple(this.tupleof).opCmp(tuple((cast(typeof(this))rhs).tupleof));
57 }
58
59 hash_t toHash() const
60 {
61 hash_t v = 0;
62 foreach(mem; this.tupleof) {
63 v *= 11;
64 static if(__traits(compiles, v^=mem))
65 v ^= mem;
66 else
67 v ^= typeid(mem).getHash(&mem);
68 }
69 return v;
70 }
71 }
72
73 template DeriveShow()
74 {
75 override:
76 string toString() const
77 {
78 string str = text(typeof(this).stringof, "(");
79 foreach(i,mem; this.tupleof) {
80 if(i) str ~= ", ";
81 str = text(str, this.tupleof[i].stringof[5..$], ":", mem);
82 }
83 return str ~ ")";
84 }
85 }