refCounted

Constructs a new array with size elements and wraps it in a $(D_PSYMBOL RefCounted).

  1. RefCounted!T refCounted(Allocator allocator, A args)
  2. RefCounted!T refCounted(Allocator allocator, size_t size)
    @trusted
    refCounted
    (
    T : E[]
    E
    )
    (,
    size_t size
    )

Parameters

T

Array type.

E

Array element type.

size size_t

Array size.

allocator Allocator

Allocator.

Return Value

Type: RefCounted!T

Newly created $(D_PSYMBOL RefCounted!T).

Precondition: allocator !is null && size <= size_t.max / E.sizeof

Examples

auto rc = defaultAllocator.refCounted!int(5);
assert(rc.count == 1);

void func(RefCounted!int param) @nogc
{
    if (param.count == 2)
    {
        func(param);
    }
    else
    {
        assert(param.count == 3);
    }
}
func(rc);

assert(rc.count == 1);

Meta