src/fusion/smartptrs

C++11 like Smart pointers. It always uses the shared allocator.

Types

ConstPtr[T] = distinct SharedPtr[T]
Distinct version of referencing counting smart pointer SharedPtrT, which doesn't allow mutating underlying object.
SharedPtr[T] = object
Shared ownership reference counting pointer
UniquePtr[T] = object
Non copyable pointer to object T, exclusive ownership of the object is assumed.

Procs

proc `$`[T](p: ConstPtr[T]): string {.inline.}
proc `$`[T](p: SharedPtr[T]): string {.inline.}
proc `$`[T](p: UniquePtr[T]): string {.inline.}
proc `=`[T](dest: var SharedPtr[T]; src: SharedPtr[T])
proc `=`[T](dest: var UniquePtr[T]; src: UniquePtr[T]) {.error.}
proc `=destroy`[T](p: var SharedPtr[T]) {....raises: [].}
proc `=destroy`[T](p: var UniquePtr[T]) {....raises: [].}
proc `[]`[T](p: ConstPtr[T]): lent T {.inline.}
proc `[]`[T](p: SharedPtr[T]): var T {.inline.}
proc `[]`[T](p: UniquePtr[T]): var T {.inline.}
proc `[]=`[T](p: SharedPtr[T]; v: T) {.inline.}
proc `[]=`[T](p: UniquePtr[T]; v: T) {.inline.}
proc isNil[T](p: ConstPtr[T]): bool {.inline.}
proc isNil[T](p: SharedPtr[T]): bool {.inline.}
proc isNil[T](p: UniquePtr[T]): bool {.inline.}
proc newConstPtr[T](val: sink T): ConstPtr[T]
proc newSharedPtr[T](val: sink T): SharedPtr[T] {.nodestroy.}
proc newUniquePtr[T](val: sink T): UniquePtr[T] {.nodestroy.}

Converters

converter convertConstPtrToObj[T](p: ConstPtr[T]): lent T {.inline.}
converter convertSharedPtrToObj[T](p: SharedPtr[T]): var T {.inline.}
converter convertUniquePtrToObj[T](p: UniquePtr[T]): var T {.inline.}

Templates

template `[]=`[T](p: ConstPtr[T]; v: T)