tstaticprocparams.nim 621 B

1234567891011121314151617
  1. proc consumer[T: static proc(i: int): int{.nimcall.}](i: int): int = T(i)
  2. proc consumer(T: static proc(i: int): int{.nimcall.}, i: int): int = T(i)
  3. proc addIt(i: int): int = i + i
  4. proc add(i: int): int = i + i # Checks if we can use overloads
  5. proc squareIt(i: int): int = i * i
  6. assert consumer[addIt](10) == 20
  7. assert consumer[add](10) == 20
  8. assert consumer[squareIt](30) == 900
  9. assert consumer[proc(i: int): int{.nimcall.} = i * i + i](10) == 110
  10. assert consumer(addIt, 10) == 20
  11. assert consumer(add, 10) == 20
  12. assert consumer(squareIt, 30) == 900
  13. assert consumer(proc(i: int): int{.nimcall.} = i * i + i, 10) == 110