containers.dynamicarray
Dynamic Array
License
-
Declaration
struct
DynamicArray
(T, Allocator = Mallocator, bool supportGC = shouldAddGCRange!T);Array that is able to grow itself when items are appended to it. Uses malloc/free/realloc to manage its storage.
Parameters
T
the array element type
Allocator
the allocator to use. Defaults to
Mallocator
.supportGC
true
if the container should support holding references to GC-allocated memory.-
Declaration
alias
AppendT
= const(T);Either
const(T)
orT
. -
Declaration
alias
AppendTypeOfThis
= const(typeof(this));Either
const(typeof(this))
ortypeof(this)
. -
Declaration
this();
No default construction if an allocator must be provided.
-
Declaration
this(Allocator
allocator
);Use the given
for allocations.allocator
-
Declaration
@nogc auto
opSlice
(this This)();
@nogc autoopSlice
(this This)(size_ta
, size_tb
);Slice operator overload
-
Declaration
@nogc auto
opIndex
(this This)(size_ti
);Index operator overload
-
Declaration
void
insertBack
(Tvalue
);
aliasinsert
= insertBack;
aliasinsertAnywhere
= insertBack;
aliasput
= insertBack;Inserts the given
value
into the end of the array. -
Declaration
ref scope typeof(this)
opOpAssign
(string op)(Tvalue
) if (op == "~");~= operator overload
-
Declaration
ref scope typeof(this)
opOpAssign
(string op, bool checkForOverlap = true)(AppendT[]rhs
) if (op == "~" && !is(T == AppendT[]));
ref scope typeof(this)opOpAssign
(string op)(ref AppendTypeOfThisrhs
) if (op == "~");~= operator overload for an array of items
-
Declaration
typeof(this)
opBinary
(string op)(ref AppendTypeOfThisother
) if (op == "~");
typeof(this)opBinary
(string op)(AppendT[]values
) if (op == "~");~ operator overload
-
Declaration
void
reserve
(size_tn
);Ensures sufficient capacity to accommodate
elements.n
-
Declaration
void
resize
(size_tn
);Change the array length. When growing, initialize new elements to the default value.
-
Declaration
void
resize
(size_tn
, Tvalue
);Change the array length. When growing, initialize new elements to the given
value
. -
Declaration
void
remove
(const size_ti
);Remove the item at the given index from the array.
-
Declaration
void
removeBack
();Removes the last element from the array.
-
Declaration
@nogc void
opIndexAssign
(Tvalue
, size_ti
);Index assignment support
-
Declaration
@nogc void
opSliceAssign
(Tvalue
);
@nogc voidopSliceAssign
(Tvalue
, size_ti
, size_tj
);Slice assignment support
-
Declaration
const pure nothrow @nogc @property @safe size_t
length
();
aliasopDollar
= length;Return Value
the number of items in the array
-
Declaration
const pure nothrow @nogc @property @safe bool
empty
();Return Value
whether or not the DynamicArray is
empty
. -
Declaration
@nogc @property auto
ptr
(this This)();Return Value
a slice to the underlying array.
As the memory of the array may be freed, access to this array is highly unsafe. -
Declaration
pure @property ref T
front
();Return Value
the
front
element of the DynamicArray. -
Declaration
pure @property ref T
back
();Return Value
the
back
element of the DynamicArray.
-