sync/smartptrs

Source   Edit  

C++11 like smart pointers. They always use the shared allocator.

Types

ConstPtr[T] = distinct SharedPtr[T]
Distinct version of SharedPtr[T], which doesn't allow mutating the underlying value. Source   Edit  
SharedPtr[T] = object
  
Shared ownership reference counting pointer. Source   Edit  
UniquePtr[T] = object
  
Non copyable pointer to a value of type T with exclusive ownership. Source   Edit  

Procs

proc `$`[T](p: ConstPtr[T]): string {.inline.}
Source   Edit  
proc `$`[T](p: SharedPtr[T]): string {.inline.}
Source   Edit  
proc `$`[T](p: UniquePtr[T]): string {.inline.}
Source   Edit  
proc `=copy`[T](dest: var SharedPtr[T]; src: SharedPtr[T])
Source   Edit  
proc `=copy`[T](dest: var UniquePtr[T]; src: UniquePtr[T]) {.error.}
The copy operation is disallowed for UniquePtr, it can only be moved. Source   Edit  
proc `=destroy`[T](p: var SharedPtr[T])
Source   Edit  
proc `=destroy`[T](p: var UniquePtr[T])
Source   Edit  
proc `[]`[T](p: ConstPtr[T]): lent T {.inline.}
Returns an immutable view of the internal value of p. Source   Edit  
proc `[]`[T](p: SharedPtr[T]): var T {.inline.}
Source   Edit  
proc `[]`[T](p: UniquePtr[T]): var T {.inline.}
Returns a mutable view of the internal value of p. Source   Edit  
proc `[]=`[T](p: ConstPtr[T]; v: T)
Source   Edit  
proc `[]=`[T](p: SharedPtr[T]; val: sink Isolated[T]) {.inline.}
Source   Edit  
proc `[]=`[T](p: UniquePtr[T]; val: sink Isolated[T]) {.inline.}
Source   Edit  
proc isNil[T](p: ConstPtr[T]): bool {.inline.}
Source   Edit  
proc isNil[T](p: SharedPtr[T]): bool {.inline.}
Source   Edit  
proc isNil[T](p: UniquePtr[T]): bool {.inline.}
Source   Edit  
proc newConstPtr[T](val: sink Isolated[T]): ConstPtr[T] {.nodestroy, inline.}
Similar to newSharedPtr, but the underlying value can't be mutated. Source   Edit  
proc newSharedPtr[T](t: typedesc[T]): SharedPtr[T]
Returns a shared pointer. It is not initialized, so reading from it before writing to it is undefined behaviour! Source   Edit  
proc newSharedPtr[T](val: sink Isolated[T]): SharedPtr[T] {.nodestroy.}
Returns a shared pointer which shares ownership of the object by reference counting. Source   Edit  
proc newUniquePtr[T](t: typedesc[T]): UniquePtr[T]
Returns a unique pointer. It is not initialized, so reading from it before writing to it is undefined behaviour! Source   Edit  
proc newUniquePtr[T](val: sink Isolated[T]): UniquePtr[T] {.nodestroy.}
Returns a unique pointer which has exclusive ownership of the value. Source   Edit  

Templates

template `[]=`[T](p: SharedPtr[T]; val: T)
Source   Edit  
template `[]=`[T](p: UniquePtr[T]; val: T)
Source   Edit  
template newConstPtr[T](val: T): ConstPtr[T]
Source   Edit  
template newSharedPtr[T](val: T): SharedPtr[T]
Source   Edit  
template newUniquePtr[T](val: T): UniquePtr[T]
Source   Edit