temitlist.nim 862 B

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