summary refs log tree commit diff stats
path: root/tests/cpp/temitlist.nim
blob: a7a8ebde47208ba7b44db7fccc5c2c6397ada52e (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 """
  targets: "cpp"
  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()