tsharedlist.nim 801 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. discard """
  2. matrix: "--mm:orc; --mm:refc"
  3. """
  4. import std/sharedlist
  5. import std/assertions
  6. block:
  7. var
  8. list: SharedList[int]
  9. count: int
  10. init(list)
  11. for i in 1 .. 250:
  12. list.add i
  13. for i in list:
  14. inc count
  15. doAssert count == 250
  16. deinitSharedList(list)
  17. block: # bug #17696
  18. var keysList = SharedList[string]()
  19. init(keysList)
  20. keysList.add("a")
  21. keysList.add("b")
  22. keysList.add("c")
  23. keysList.add("d")
  24. keysList.add("e")
  25. keysList.add("f")
  26. # Remove element "b" and "d" from the list.
  27. keysList.iterAndMutate(proc (key: string): bool =
  28. if key == "b" or key == "d": # remove only "b" and "d"
  29. return true
  30. return false
  31. )
  32. var results: seq[string]
  33. for key in keysList.items:
  34. results.add key
  35. doAssert results == @["a", "f", "c", "e"]