RingBuffer

Members

Functions

clear
void clear()

empty the buffer

opAssign
void opAssign(R rhs)

assignment

opIndex
auto opIndex()

range interface

opIndex
auto opIndex(size_t index)
opOpAssign
void opOpAssign(DataType rhs)
void opOpAssign(R rhs)

push to buffer (lifo)

pop
DataType pop()

retrieve item from buffer (lifo)

push
void push(DataType rhs)
void push(R rhs)

push to buffer (lifo)

shift
DataType shift()

retrieve item from buffer (fifo)

unshift
void unshift(DataType rhs)
void unshift(R rhs)

push to buffer (fifo)

Properties

capacity
auto capacity [@property getter]
length
auto length [@property getter]

Examples

example

RingBuffer!(int, 5) buff;
buff.push(69);
buff ~= 420; // equivalent to the push syntax
assert(buff.shift == 69);
assert(buff.shift == 420);

import std.array : staticArray;
import std.range : iota;
immutable int[5] temp = staticArray!(iota(5));

buff.push(temp); // multiple items may be pushed in a single call

assert(buff.length == 5);
assert(buff.capacity == 0);

assert(buff.pop == 4);

assert(buff.length == 4);
assert(buff.capacity == 1);

buff.unshift(666);
assert(buff.shift == 666);

buff.clear();

assert(buff.length == 0);
assert(buff.capacity == 5);

Meta