PageRenderTime 48ms CodeModel.GetById 21ms 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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. module overload_template_runme;
  2. import overload_template.overload_template;
  3. import overload_template.Klass;
  4. void main() {
  5. int f = foo();
  6. f += maximum(3,4);
  7. double b = maximum(3.4,5.2);
  8. b++; // warning suppression
  9. // mix 1
  10. if (mix1("hi") != 101)
  11. throw new Exception ("mix1(const char*)");
  12. if (mix1(1.0, 1.0) != 102)
  13. throw new Exception ("mix1(double, const double &)");
  14. if (mix1(1.0) != 103)
  15. throw new Exception ("mix1(double)");
  16. // mix 2
  17. if (mix2("hi") != 101)
  18. throw new Exception ("mix2(const char*)");
  19. if (mix2(1.0, 1.0) != 102)
  20. throw new Exception ("mix2(double, const double &)");
  21. if (mix2(1.0) != 103)
  22. throw new Exception ("mix2(double)");
  23. // mix 3
  24. if (mix3("hi") != 101)
  25. throw new Exception ("mix3(const char*)");
  26. if (mix3(1.0, 1.0) != 102)
  27. throw new Exception ("mix3(double, const double &)");
  28. if (mix3(1.0) != 103)
  29. throw new Exception ("mix3(double)");
  30. // Combination 1
  31. if (overtparams1(100) != 10)
  32. throw new Exception ("overtparams1(int)");
  33. if (overtparams1(100.0, 100) != 20)
  34. throw new Exception ("overtparams1(double, int)");
  35. // Combination 2
  36. if (overtparams2(100.0, 100) != 40)
  37. throw new Exception ("overtparams2(double, int)");
  38. // Combination 3
  39. if (overloaded() != 60)
  40. throw new Exception ("overloaded()");
  41. if (overloaded(100.0, 100) != 70)
  42. throw new Exception ("overloaded(double, int)");
  43. // Combination 4
  44. if (overloadedagain("hello") != 80)
  45. throw new Exception ("overloadedagain(const char *)");
  46. if (overloadedagain() != 90)
  47. throw new Exception ("overloadedagain(double)");
  48. // specializations
  49. if (specialization(10) != 202)
  50. throw new Exception ("specialization(int)");
  51. if (specialization(10.0) != 203)
  52. throw new Exception ("specialization(double)");
  53. if (specialization(10, 10) != 204)
  54. throw new Exception ("specialization(int, int)");
  55. if (specialization(10.0, 10.0) != 205)
  56. throw new Exception ("specialization(double, double)");
  57. if (specialization("hi", "hi") != 201)
  58. throw new Exception ("specialization(const char *, const char *)");
  59. // simple specialization
  60. xyz();
  61. xyz_int();
  62. xyz_double();
  63. // a bit of everything
  64. if (overload("hi") != 0)
  65. throw new Exception ("overload()");
  66. if (overload(1) != 10)
  67. throw new Exception ("overload(int t)");
  68. if (overload(1, 1) != 20)
  69. throw new Exception ("overload(int t, const int &)");
  70. if (overload(1, "hello") != 30)
  71. throw new Exception ("overload(int t, const char *)");
  72. auto k = new Klass();
  73. if (overload(k) != 10)
  74. throw new Exception ("overload(Klass t)");
  75. if (overload(k, k) != 20)
  76. throw new Exception ("overload(Klass t, const Klass &)");
  77. if (overload(k, "hello") != 30)
  78. throw new Exception ("overload(Klass t, const char *)");
  79. if (overload(10.0, "hi") != 40)
  80. throw new Exception ("overload(double t, const char *)");
  81. if (overload() != 50)
  82. throw new Exception ("overload(const char *)");
  83. // everything put in a namespace
  84. if (nsoverload("hi") != 1000)
  85. throw new Exception ("nsoverload()");
  86. if (nsoverload(1) != 1010)
  87. throw new Exception ("nsoverload(int t)");
  88. if (nsoverload(1, 1) != 1020)
  89. throw new Exception ("nsoverload(int t, const int &)");
  90. if (nsoverload(1, "hello") != 1030)
  91. throw new Exception ("nsoverload(int t, const char *)");
  92. if (nsoverload(k) != 1010)
  93. throw new Exception ("nsoverload(Klass t)");
  94. if (nsoverload(k, k) != 1020)
  95. throw new Exception ("nsoverload(Klass t, const Klass &)");
  96. if (nsoverload(k, "hello") != 1030)
  97. throw new Exception ("nsoverload(Klass t, const char *)");
  98. if (nsoverload(10.0, "hi") != 1040)
  99. throw new Exception ("nsoverload(double t, const char *)");
  100. if (nsoverload() != 1050)
  101. throw new Exception ("nsoverload(const char *)");
  102. }