Struct RingBuffer

Owning bounded FIFO ring buffer with runtime-selected capacity.

struct RingBuffer(T);

The backing storage is acquired once at construction and retained across push/pop/clear operations. Exactly length slots contain live T objects.

Copy construction is disabled because backing storage is uniquely owned. Whole-buffer move transfers ownership in O(1) without relocating live elements.

Constructors

NameDescription
this (capacity) Acquires backing storage for capacity elements.
this (rhs) Unique owning storage is never copied implicitly.
this (rhs) Transfers backing-storage ownership in O(1).

Methods

NameDescription
back () Mutable logical back element.
capacity () Maximum number of live elements.
clear () Destroys all live elements while retaining the backing allocation.
empty () Whether no live elements are stored.
firstSegment () Returns the first contiguous physical segment in logical FIFO order.
front () Mutable logical front element.
full () Whether no additional element can be inserted.
length () Number of live elements.
opAssign (rhs) Identity assignment remains unavailable in the first owning API.
opIndex (logicalIndex) Mutable logical indexed access independent of physical wraparound.
popFront () Destroys and removes the logical front element.
secondSegment () Returns the wrapped continuation after firstSegment.
tryPushBack (value) Appends one element without overwriting existing contents.

Example

auto queue = RingBuffer!int(4);
assert(queue.tryPushBack(10));
assert(queue.tryPushBack(20));
queue.popFront();
assert(queue.front == 20);
assert(queue.capacity == 4);