tget_subsystem.nim 593 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. discard """
  2. targets: "cpp"
  3. """
  4. {.emit: """
  5. namespace System {
  6. struct Input {};
  7. }
  8. struct SystemManager {
  9. template <class T>
  10. static T* getSubsystem() { return new T; }
  11. };
  12. """.}
  13. type Input {.importcpp: "System::Input".} = object
  14. proc getSubsystem*[T](): ptr T {.
  15. importcpp: "SystemManager::getSubsystem<'*0>()", nodecl.}
  16. let input: ptr Input = getSubsystem[Input]()
  17. # bugs #4910, #6892
  18. proc modify(x: var int) =
  19. x = 123
  20. proc foo() =
  21. var ts: array[2, int]
  22. for t in mitems(ts):
  23. discard
  24. for t in mitems(ts):
  25. modify(t)
  26. for i, t in mpairs(ts):
  27. modify(t)