temitlist.nim 863 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. discard """
  2. targets: "cpp"
  3. output: '''
  4. 6.0
  5. 0'''
  6. """
  7. # bug #4730
  8. type Vector*[T] {.importcpp: "std::vector", header: "<vector>".} = object
  9. template `[]=`*[T](v: var Vector[T], key: int, val: T) =
  10. {.emit: [v, "[", key, "] = ", val, ";"].}
  11. proc setLen*[T](v: var Vector[T]; size: int) {.importcpp: "resize", nodecl.}
  12. proc `[]`*[T](v: var Vector[T], key: int): T {.importcpp: "(#[#])", nodecl.}
  13. proc main =
  14. var v: Vector[float]
  15. v.setLen 1
  16. v[0] = 6.0
  17. echo v[0]
  18. main()
  19. #------------
  20. #bug #6837
  21. type StdString {.importCpp: "std::string", header: "<string>", byref.} = object
  22. proc initString(): StdString {.constructor, importCpp: "std::string(@)", header: "<string>".}
  23. proc size(this: var StdString): csize_t {.importCpp: "size", header: "<string>".}
  24. proc f(): csize_t =
  25. var myString: StdString = initString()
  26. return myString.size()
  27. echo f()