Files
Nim/tests/run/tmemoization.nim
Zahary Karadjov 22dc76a361 typedesc and expr params
types are now valid proc/template/macro params and you can overload over them:
proc foo(T: typedesc)        # accept any type
proc foo(T: typedesc{int}) # overload specifically for int
proc foo(T: typedesc{int or float or Callable}) # overload for any type matching the constraints

expr{type} is a param expecting compile time value of the designated type (or type class).

when typedesc or expr params are used with a proc, the proc will be instantiated once
for each unique type/value used as parameter.
2012-03-31 18:50:48 +03:00

18 lines
248 B
Nim

discard """
msg: "test 1\ntest 2"
output: "TEST 1\nTEST 2\nTEST 2"
"""
import strutils
proc foo(s: expr{string}): string =
static: echo s
const R = s.toUpper
return R
echo foo("test 1")
echo foo("test 2")
echo foo("test " & $2)