PageRenderTime 36ms CodeModel.GetById 1ms app.highlight 33ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/d/overload_template_runme.1.d

#
D | 146 lines | 91 code | 44 blank | 11 comment | 78 complexity | c8d9de157f3e19d29a9902090185cc20 MD5 | raw file
  1module overload_template_runme;
  2
  3import overload_template.overload_template;
  4import overload_template.Klass;
  5
  6void main() {
  7  int f = foo();
  8
  9  f += maximum(3,4);
 10  double b = maximum(3.4,5.2);
 11  b++; // warning suppression
 12
 13  // mix 1
 14  if (mix1("hi") != 101)
 15    throw new Exception ("mix1(const char*)");
 16
 17  if (mix1(1.0, 1.0) != 102)
 18    throw new Exception ("mix1(double, const double &)");
 19
 20  if (mix1(1.0) != 103)
 21    throw new Exception ("mix1(double)");
 22
 23  // mix 2
 24  if (mix2("hi") != 101)
 25    throw new Exception ("mix2(const char*)");
 26
 27  if (mix2(1.0, 1.0) != 102)
 28    throw new Exception ("mix2(double, const double &)");
 29
 30  if (mix2(1.0) != 103)
 31    throw new Exception ("mix2(double)");
 32
 33  // mix 3
 34  if (mix3("hi") != 101)
 35    throw new Exception ("mix3(const char*)");
 36
 37  if (mix3(1.0, 1.0) != 102)
 38    throw new Exception ("mix3(double, const double &)");
 39
 40  if (mix3(1.0) != 103)
 41    throw new Exception ("mix3(double)");
 42
 43  // Combination 1
 44  if (overtparams1(100) != 10)
 45    throw new Exception ("overtparams1(int)");
 46
 47  if (overtparams1(100.0, 100) != 20)
 48    throw new Exception ("overtparams1(double, int)");
 49
 50  // Combination 2
 51  if (overtparams2(100.0, 100) != 40)
 52    throw new Exception ("overtparams2(double, int)");
 53
 54  // Combination 3
 55  if (overloaded() != 60)
 56    throw new Exception ("overloaded()");
 57
 58  if (overloaded(100.0, 100) != 70)
 59    throw new Exception ("overloaded(double, int)");
 60
 61  // Combination 4
 62  if (overloadedagain("hello") != 80)
 63    throw new Exception ("overloadedagain(const char *)");
 64
 65  if (overloadedagain() != 90)
 66    throw new Exception ("overloadedagain(double)");
 67
 68  // specializations
 69  if (specialization(10) != 202)
 70    throw new Exception ("specialization(int)");
 71
 72  if (specialization(10.0) != 203)
 73    throw new Exception ("specialization(double)");
 74
 75  if (specialization(10, 10) != 204)
 76    throw new Exception ("specialization(int, int)");
 77
 78  if (specialization(10.0, 10.0) != 205)
 79    throw new Exception ("specialization(double, double)");
 80
 81  if (specialization("hi", "hi") != 201)
 82    throw new Exception ("specialization(const char *, const char *)");
 83
 84  // simple specialization
 85  xyz();
 86  xyz_int();
 87  xyz_double();
 88
 89  // a bit of everything
 90  if (overload("hi") != 0)
 91    throw new Exception ("overload()");
 92
 93  if (overload(1) != 10)
 94    throw new Exception ("overload(int t)");
 95
 96  if (overload(1, 1) != 20)
 97    throw new Exception ("overload(int t, const int &)");
 98
 99  if (overload(1, "hello") != 30)
100    throw new Exception ("overload(int t, const char *)");
101
102  auto k = new Klass();
103  if (overload(k) != 10)
104    throw new Exception ("overload(Klass t)");
105
106  if (overload(k, k) != 20)
107    throw new Exception ("overload(Klass t, const Klass &)");
108
109  if (overload(k, "hello") != 30)
110    throw new Exception ("overload(Klass t, const char *)");
111
112  if (overload(10.0, "hi") != 40)
113    throw new Exception ("overload(double t, const char *)");
114
115  if (overload() != 50)
116    throw new Exception ("overload(const char *)");
117
118
119  // everything put in a namespace
120  if (nsoverload("hi") != 1000)
121    throw new Exception ("nsoverload()");
122
123  if (nsoverload(1) != 1010)
124    throw new Exception ("nsoverload(int t)");
125
126  if (nsoverload(1, 1) != 1020)
127    throw new Exception ("nsoverload(int t, const int &)");
128
129  if (nsoverload(1, "hello") != 1030)
130    throw new Exception ("nsoverload(int t, const char *)");
131
132  if (nsoverload(k) != 1010)
133    throw new Exception ("nsoverload(Klass t)");
134
135  if (nsoverload(k, k) != 1020)
136    throw new Exception ("nsoverload(Klass t, const Klass &)");
137
138  if (nsoverload(k, "hello") != 1030)
139    throw new Exception ("nsoverload(Klass t, const char *)");
140
141  if (nsoverload(10.0, "hi") != 1040)
142    throw new Exception ("nsoverload(double t, const char *)");
143
144  if (nsoverload() != 1050)
145    throw new Exception ("nsoverload(const char *)");
146}