containers.dynamicarray

Dynamic Array

Authors

Brian Schott

  • 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) or T.

    • Declaration

      alias AppendTypeOfThis = const(typeof(this));

      Either const(typeof(this)) or typeof(this).

    • Declaration

      this();

      No default construction if an allocator must be provided.

    • Declaration

      this(Allocator allocator);

      Use the given allocator for allocations.

    • Declaration

      @nogc auto opSlice(this This)();
      @nogc auto opSlice(this This)(size_t a, size_t b);

      Slice operator overload

    • Declaration

      @nogc auto opIndex(this This)(size_t i);

      Index operator overload

    • Declaration

      void insertBack(T value);
      alias insert = insertBack;
      alias insertAnywhere = insertBack;
      alias put = insertBack;

      Inserts the given value into the end of the array.

    • Declaration

      ref scope typeof(this) opOpAssign(string op)(T value) 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 AppendTypeOfThis rhs) if (op == "~");

      ~= operator overload for an array of items

    • Declaration

      typeof(this) opBinary(string op)(ref AppendTypeOfThis other) if (op == "~");
      typeof(this) opBinary(string op)(AppendT[] values) if (op == "~");

      ~ operator overload

    • Declaration

      void reserve(size_t n);

      Ensures sufficient capacity to accommodate n elements.

    • Declaration

      void resize(size_t n);

      Change the array length. When growing, initialize new elements to the default value.

    • Declaration

      void resize(size_t n, T value);

      Change the array length. When growing, initialize new elements to the given value.

    • Declaration

      void remove(const size_t i);

      Remove the item at the given index from the array.

    • Declaration

      void removeBack();

      Removes the last element from the array.

    • Declaration

      @nogc void opIndexAssign(T value, size_t i);

      Index assignment support

    • Declaration

      @nogc void opSliceAssign(T value);
      @nogc void opSliceAssign(T value, size_t i, size_t j);

      Slice assignment support

    • Declaration

      const pure nothrow @nogc @property @safe size_t length();
      alias opDollar = 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.

    • ptr

      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.