SharedPtr

Implementation of a ref counted pointer with support for aliasing.

SharedPtr retains shared ownership of an object through a pointer.

Several SharedPtr objects may own the same object.

The object is destroyed and its memory deallocated when either of the following happens:

1. the last remaining SharedPtr owning the object is destroyed.

2. the last remaining SharedPtr owning the object is assigned another pointer via various methods like opAssign and store.

The object is destroyed using delete-expression or a custom deleter that is supplied to SharedPtr during construction.

A SharedPtr can share ownership of an object while storing a pointer to another object. This feature can be used to point to member objects while owning the object they belong to. The stored pointer is the one accessed by get(), the dereference and the comparison operators. The managed pointer is the one passed to the deleter when use count reaches zero.

A SharedPtr may also own no objects, in which case it is called empty (an empty SharedPtr may have a non-null stored pointer if the aliasing constructor was used to create it).

If template parameter _ControlType is shared then all member functions (including copy constructor and copy assignment) can be called by multiple threads on different instances of SharedPtr without additional synchronization even if these instances are copies and share ownership of the same object.

If multiple threads of execution access the same SharedPtr (shared SharedPtr) then only some methods can be called (load, store, exchange, compareExchange, useCount).

Template parameters:

_Type type of managed object

_DestructorType function pointer with attributes of destructor, to get attributes of destructor from type use btl.autoptr.common.DestructorType!T. Destructor of type _Type must be compatible with _DestructorType

_ControlType represent type of counter, must by of type btl.autoptr.common.ControlBlock. if is shared then ref counting is atomic.

_weakPtr if true then SharedPtr represent weak ptr

  1. template SharedPtr(_Type, _DestructorType = DestructorType!_Type, _ControlType = ControlBlockDeduction!(_Type, SharedControlBlock), bool _weakPtr = false)
    template SharedPtr (
    _Type
    _DestructorType = DestructorType!_Type
    _ControlType = ControlBlockDeduction!(_Type, SharedControlBlock)
    bool _weakPtr = false
    ) if (
    isControlBlock!_ControlType &&
    isDestructorType!_DestructorType
    ) {}
  2. template SharedPtr(_Type, _ControlType, _DestructorType = DestructorType!_Type, bool _weakPtr = false)

Members

Aliases

ElementDestructorType
alias ElementDestructorType() = .DestructorType!_Type
Undocumented in source.
ElementDestructorType
alias ElementDestructorType() = .DestructorType!void
Undocumented in source.

Functions

check_dtor
void check_dtor()
Undocumented in source. Be warned that the author may not have intended to support it.

Imports

AliasSeq (from std.meta)
public import std.meta : AliasSeq;
Undocumented in source.
CopyConstness (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
CopyTypeQualifiers (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
ElementEncodingType (from std.range)
public import std.range : ElementEncodingType;
Undocumented in source.
MemoryOrder (from core.atomic)
public import core.atomic : MemoryOrder;
Undocumented in source.
Select (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
Unconst (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
Unqual (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
forward (from core.lifetime)
public import core.lifetime : forward;
Undocumented in source.
hasElaborateDestructor (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
hasIndirections (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
isAbstractClass (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
isArray (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
isCallable (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
isDynamicArray (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
isMutable (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.
isStaticArray (from std.traits)
public import std.traits : Unqual, Unconst, CopyTypeQualifiers, CopyConstness, hasIndirections, hasElaborateDestructor, isMutable, isAbstractClass, isDynamicArray, isStaticArray, isCallable, Select, isArray;
Undocumented in source.

Structs

SharedPtr
struct SharedPtr
Undocumented in source.

Variables

_isLockFree
enum bool _isLockFree;
Undocumented in source.
hasSharedCounter
enum bool hasSharedCounter;
Undocumented in source.
hasWeakCounter
enum bool hasWeakCounter;
Undocumented in source.
referenceElementType
enum bool referenceElementType;
Undocumented in source.

Meta