tmodifiersinplace.nim 639 B

12345678910111213141516171819202122232425262728293031
  1. type
  2. VarContainer[T] = concept c
  3. put(var c, T)
  4. AltVarContainer[T] = concept var c
  5. put(c, T)
  6. NonVarContainer[T] = concept c
  7. put(c, T)
  8. GoodContainer = object
  9. x: int
  10. BadContainer = object
  11. x: int
  12. proc put(x: BadContainer, y: int) = discard
  13. proc put(x: var GoodContainer, y: int) = discard
  14. template ok(x) = assert(x)
  15. template no(x) = assert(not(x))
  16. static:
  17. ok GoodContainer is VarContainer[int]
  18. ok GoodContainer is AltVarContainer[int]
  19. no BadContainer is VarContainer[int]
  20. no BadContainer is AltVarContainer[int]
  21. ok GoodContainer is NonVarContainer[int]
  22. ok BadContainer is NonVarContainer[int]