tforwardgenericconstrained.nim 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. discard """
  2. output: '''
  3. hello some integer
  4. hello range
  5. hello tuple
  6. hello seq
  7. hello object
  8. hello distinct
  9. hello enum
  10. '''
  11. """
  12. # SomeInteger
  13. proc foo[T : SomeInteger](arg: T)
  14. proc foo[T : SomeInteger](arg: T) =
  15. echo "hello some integer"
  16. foo(123)
  17. # range
  18. proc foo2[T : range[0..100]](arg: T)
  19. proc foo2[T : range[0..100]](arg: T) =
  20. echo "hello range"
  21. foo2(7)
  22. # tuple
  23. proc foo3[T : tuple](arg: T)
  24. proc foo3[T : tuple](arg: T) =
  25. echo "hello tuple"
  26. foo3((a:123,b:321))
  27. # seq
  28. proc foo4[T: seq](arg: T)
  29. proc foo4[T: seq](arg: T) =
  30. echo "hello seq"
  31. foo4(@[1,2,3])
  32. # object
  33. proc foo5[T : object](arg: T)
  34. proc foo5[T : object](arg: T) =
  35. echo "hello object"
  36. type MyType = object
  37. var mt: MyType
  38. foo5(mt)
  39. # distinct
  40. proc foo6[T : distinct](arg: T)
  41. proc foo6[T : distinct](arg: T) =
  42. echo "hello distinct"
  43. type MyDistinct = distinct string
  44. var md: MyDistinct
  45. foo6(md)
  46. # enum
  47. proc foo7[T : enum](arg: T)
  48. proc foo7[T : enum](arg: T) =
  49. echo "hello enum"
  50. type MyEnum = enum
  51. ValueA
  52. foo7(ValueA)