summary refs log tree commit diff stats
path: root/tests/overload/tparam_forwarding.nim
blob: c1b276bfc9c2a712f483f78730bf36193e8ccc30 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
discard """
output: '''baz
10
100
1000
a
b
c
'''
"""

type
  Foo = object
    x: int

proc stringVarargs*(strings: varargs[string, `$`]): void =
  for s in strings: echo s

proc fooVarargs*(foos: varargs[Foo]) =
  for f in foos: echo f.x

template templateForwarding*(callable: untyped,
                             condition: bool,
                             forwarded: varargs[untyped]): untyped =
  if condition:
    callable(forwarded)

proc procForwarding(args: varargs[string]) =
  stringVarargs(args)

templateForwarding stringVarargs, 17 + 4 < 21, "foo", "bar", 100
templateForwarding stringVarargs, 10 < 21, "baz"

templateForwarding fooVarargs, "test".len > 3, Foo(x: 10), Foo(x: 100), Foo(x: 1000)

procForwarding "a", "b", "c"