summary refs log tree commit diff stats
path: root/tests/cpp/temitlist.nim
blob: cef0fc52d7ef066abb0a344a16cfde7e9adafac5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
discard """
  cmd: "nim cpp $file"
  output: '''6.0'''
"""

# bug #4730

type Vector* {.importcpp: "std::vector", header: "<vector>".}[T] = object

template `[]=`*[T](v: var Vector[T], key: int, val: T) =
  {.emit: [v, "[", key, "] = ", val, ";"].}

proc setLen*[T](v: var Vector[T]; size: int) {.importcpp: "resize", nodecl.}
proc `[]`*[T](v: var Vector[T], key: int): T {.importcpp: "(#[#])", nodecl.}

proc main =
  var v: Vector[float]
  v.setLen 1
  v[0] = 6.0
  echo v[0]

main()