no commas for empty importcpp splat params (#12183)
This commit is contained in:
parent
5783cd67a8
commit
ca7bf3be8b
2 changed files with 17 additions and 7 deletions
|
|
@ -394,11 +394,14 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope =
|
||||||
while i < pat.len:
|
while i < pat.len:
|
||||||
case pat[i]
|
case pat[i]
|
||||||
of '@':
|
of '@':
|
||||||
if j < ri.len:
|
var first = true
|
||||||
result.add genOtherArg(p, ri, j, typ)
|
for k in j ..< ri.len:
|
||||||
for k in j+1 ..< ri.len:
|
let arg = genOtherArg(p, ri, k, typ)
|
||||||
result.add(~", ")
|
if arg.len > 0:
|
||||||
result.add genOtherArg(p, ri, k, typ)
|
if not first:
|
||||||
|
result.add(~", ")
|
||||||
|
first = false
|
||||||
|
result.add arg
|
||||||
inc i
|
inc i
|
||||||
of '#':
|
of '#':
|
||||||
if i+1 < pat.len and pat[i+1] in {'+', '@'}:
|
if i+1 < pat.len and pat[i+1] in {'+', '@'}:
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import typetraits
|
||||||
|
|
||||||
# bug #4625
|
# bug #4625
|
||||||
type
|
type
|
||||||
Vector {.importcpp: "std::vector<'0 >", header: "vector".} [T] = object
|
Vector[T] {.importcpp: "std::vector<'0 >", header: "vector".} = object
|
||||||
|
|
||||||
proc initVector[T](): Vector[T] {.importcpp: "'0(@)", header: "vector", constructor.}
|
proc initVector[T](): Vector[T] {.importcpp: "'0(@)", header: "vector", constructor.}
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ vf.doSomething() # Nim uses doSomething[int] here in C++
|
||||||
# Alternative definition:
|
# Alternative definition:
|
||||||
# https://github.com/nim-lang/Nim/issues/7653
|
# https://github.com/nim-lang/Nim/issues/7653
|
||||||
|
|
||||||
type VectorAlt* {.importcpp: "std::vector", header: "<vector>", nodecl.} [T] = object
|
type VectorAlt*[T] {.importcpp: "std::vector", header: "<vector>", nodecl.} = object
|
||||||
proc mkVector*[T]: VectorAlt[T] {.importcpp: "std::vector<'*0>()", header: "<vector>", constructor, nodecl.}
|
proc mkVector*[T]: VectorAlt[T] {.importcpp: "std::vector<'*0>()", header: "<vector>", constructor, nodecl.}
|
||||||
|
|
||||||
proc foo(): VectorAlt[cint] =
|
proc foo(): VectorAlt[cint] =
|
||||||
|
|
@ -36,3 +36,10 @@ proc bar(): VectorAlt[cstring] =
|
||||||
var x = foo()
|
var x = foo()
|
||||||
var y = bar()
|
var y = bar()
|
||||||
|
|
||||||
|
proc init[T; Self: Vector[T]](_: typedesc[Self], n: csize): Vector[T]
|
||||||
|
{.importcpp: "std::vector<'*0>(@)", header: "<vector>", constructor, nodecl.}
|
||||||
|
proc size[T](x: Vector[T]): csize
|
||||||
|
{.importcpp: "#.size()", header: "<vector>", nodecl.}
|
||||||
|
|
||||||
|
var z = Vector[int16].init(32)
|
||||||
|
assert z.size == 32
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue