temitlist.nim 486 B

1234567891011121314151617181920212223
  1. discard """
  2. cmd: "nim cpp $file"
  3. output: '''6.0'''
  4. """
  5. # bug #4730
  6. type Vector* {.importcpp: "std::vector", header: "<vector>".}[T] = object
  7. template `[]=`*[T](v: var Vector[T], key: int, val: T) =
  8. {.emit: [v, "[", key, "] = ", val, ";"].}
  9. proc setLen*[T](v: var Vector[T]; size: int) {.importcpp: "resize", nodecl.}
  10. proc `[]`*[T](v: var Vector[T], key: int): T {.importcpp: "(#[#])", nodecl.}
  11. proc main =
  12. var v: Vector[float]
  13. v.setLen 1
  14. v[0] = 6.0
  15. echo v[0]
  16. main()