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