toverload_asgn1.nim 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. discard """
  2. output: '''Concrete '='
  3. Concrete '='
  4. Concrete '='
  5. Concrete '='
  6. Concrete '='
  7. GenericT[T] '=' int
  8. GenericT[T] '=' float
  9. GenericT[T] '=' float
  10. GenericT[T] '=' float
  11. GenericT[T] '=' string
  12. GenericT[T] '=' int8
  13. GenericT[T] '=' bool
  14. GenericT[T] '=' bool
  15. GenericT[T] '=' bool
  16. GenericT[T] '=' bool'''
  17. """
  18. import typetraits
  19. type
  20. Concrete = object
  21. a, b: string
  22. proc `=`(d: var Concrete; src: Concrete) =
  23. shallowCopy(d.a, src.a)
  24. shallowCopy(d.b, src.b)
  25. echo "Concrete '='"
  26. var x, y: array[0..2, Concrete]
  27. var cA, cB: Concrete
  28. var cATup, cBTup: tuple[x: int, ha: Concrete]
  29. x = y
  30. cA = cB
  31. cATup = cBTup
  32. type
  33. GenericT[T] = object
  34. a, b: T
  35. proc `=`[T](d: var GenericT[T]; src: GenericT[T]) =
  36. shallowCopy(d.a, src.a)
  37. shallowCopy(d.b, src.b)
  38. echo "GenericT[T] '=' ", type(T).name
  39. var ag: GenericT[int]
  40. var bg: GenericT[int]
  41. ag = bg
  42. var xg, yg: array[0..2, GenericT[float]]
  43. var cAg, cBg: GenericT[string]
  44. var cATupg, cBTupg: tuple[x: int, ha: GenericT[int8]]
  45. xg = yg
  46. cAg = cBg
  47. cATupg = cBTupg
  48. var caSeqg, cbSeqg: seq[GenericT[bool]]
  49. newSeq(cbSeqg, 4)
  50. caSeqg = cbSeqg
  51. when false:
  52. type
  53. Foo = object
  54. case b: bool
  55. of false: xx: GenericT[int]
  56. of true: yy: bool
  57. var
  58. a, b: Foo
  59. a = b