temitlist.nim 904 B

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