RefCounted

Reference-counted object containing a T value as payload. $(D_PSYMBOL RefCounted) keeps track of all references of an object, and when the reference count goes down to zero, frees the underlying store.

Constructors

this
this(Payload!T value, Allocator allocator)
this(Allocator allocator)

Takes ownership over value, setting the counter to 1. value may be a pointer, an object or a dynamic array.

Destructor

~this
~this()

Decreases the reference counter by one.

Postblit

this(this)
this(this)

Increases the reference counter by one.

Alias This

get

Members

Functions

get
inout(Payload!T) get()
opAssign
typeof(this) opAssign(Payload!T rhs)
typeof(this) opAssign(typeof(null) )
typeof(this) opAssign(typeof(this) rhs)

Takes ownership over rhs. Initializes this $(D_PSYMBOL RefCounted) if needed.

opUnary
inout(T) opUnary()

Dereferences the pointer. It is defined only for pointers, not for reference types like classes, that can be accessed directly.

opUnary
inout(T) opUnary()
Undocumented in source. Be warned that the author may not have intended to support it.

Mixins

__anonymous
mixin DefaultAllocator
Undocumented in source.

Properties

count
size_t count [@property getter]
isInitialized
bool isInitialized [@property getter]

Mixed In Members

From mixin DefaultAllocator

allocator_
Allocator allocator_;

Allocator.

this
this(Allocator allocator)
allocator
shared(Allocator) allocator [@property getter]

This property checks if the allocator was set in the constructor and sets it to the default one, if not.

Parameters

T

Type of the reference-counted value.

Examples

auto rc = RefCounted!int(defaultAllocator.make!int(5), defaultAllocator);
auto val = rc.get();

*val = 8;
assert(*rc.get == 8);

val = null;
assert(rc.get !is null);
assert(*rc.get == 8);

*rc = 9;
assert(*rc.get == 9);

Meta