CyclicArray

@nogc array without memory management using a cyclic array internally Should be treated like a static array when no len is set (copies on assignment) The maximum capacity is static and by default so many elements that it fills at most 4KiB, but at least 8 elements (even if that is more than 4KiB). Set length to 0 to make it a std.container.Array based array

struct CyclicArray (
T
size_t len = max(8, 4096 / T.sizeof)
) {
Array!T array;
T[len] array;
}

Disabled Default Constructor

A disabled default is present on this object. To use it, use one of the other constructors or a factory function.

Bugs

foreach with ref value requires @nogc body to make this @nogc compatible

Examples

1 CyclicArray!int array;
2 assert(array.length == 0);
3 array ~= 5;
4 assert(!array.empty);
5 assert(array.front == 5);
6 assert(array[0] == 5);
7 array ~= [4, 3];
8 
9 assert(array == [5, 4, 3]);
10 
11 // same efficiency as insertBack/put/concat
12 array.insertFront(5);

Meta