tmanual.nim 576 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. discard """
  2. output: '''1
  3. 2
  4. 3
  5. 4
  6. 5
  7. 6
  8. a
  9. b
  10. t
  11. e
  12. s
  13. t
  14. '''
  15. """
  16. template accept(e) =
  17. static: assert compiles(e)
  18. template reject(e) =
  19. static: assert(not compiles(e))
  20. type
  21. Container[T] = concept c
  22. c.len is Ordinal
  23. items(c) is T
  24. for value in c:
  25. type(value) is T
  26. proc takesIntContainer(c: Container[int]) =
  27. for e in c: echo e
  28. takesIntContainer(@[1, 2, 3])
  29. reject takesIntContainer(@["x", "y"])
  30. proc takesContainer(c: Container) =
  31. for e in c: echo e
  32. takesContainer(@[4, 5, 6])
  33. takesContainer(@["a", "b"])
  34. takesContainer "test"
  35. reject takesContainer(10)