PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
D | 27 lines | 21 code | 4 blank | 2 comment | 6 complexity | 8e4d05a9e7b5ccd6cef1a12565c11e41 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
  1. module virtual_poly_runme;
  2. import virtual_poly.NDouble;
  3. import virtual_poly.NInt;
  4. import virtual_poly.NNumber;
  5. void main() {
  6. // D supports covariant (polymorphic) return types, so this should work like
  7. // in C++.
  8. auto d = new NDouble(3.5);
  9. NDouble dc = d.copy();
  10. if (d.get() != dc.get()) {
  11. throw new Exception("Test 1 failed.");
  12. }
  13. auto i = new NInt(2);
  14. NInt ic = i.copy();
  15. if (i.get() != ic.get()) {
  16. throw new Exception("Test 2 failed.");
  17. }
  18. NNumber n = d;
  19. auto nd = cast(NDouble) n.copy();
  20. if (nd.get() != d.get()) {
  21. throw new Exception("Test 3 failed.");
  22. }
  23. }