PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

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