tdictdestruct.nim 421 B

123456789101112131415161718192021
  1. type
  2. TDict[TK, TV] = object
  3. k: TK
  4. v: TV
  5. PDict[TK, TV] = ref TDict[TK, TV]
  6. proc fakeNew[T](x: var ref T, destroy: proc (a: ref T) {.nimcall.}) =
  7. discard
  8. proc destroyDict[TK, TV](a: PDict[TK, TV]) =
  9. return
  10. proc newDict[TK, TV](a: TK, b: TV): PDict[TK, TV] =
  11. fakeNew(result, destroyDict[TK, TV])
  12. # Problem: destroyDict is not instantiated when newDict is instantiated!
  13. discard newDict("a", "b")